Skip to main content
4 votes
3 answers
188 views

Why is having ambiguous (default) constructor due to overloading not an error or at least a warning?

The following class compiles just fine: class Time { public: Time(int h = 0, int m = 0, int s = 0); // constructor with default parameters Time(); // default ...
josch's user avatar
  • 7,290
1 vote
3 answers
114 views

Calling parameterized constructor only to update one member variable

I have a class with a default constructor which initializes many member variables via initializer lists. I wish to have a parametrized constructor which only updates one of the member variables. A ...
Engineer999's user avatar
  • 4,159
2 votes
1 answer
136 views

Member of struct constructed twice in custom constructor?

struct PhiBlock { int64_t bsize; // block size vector<int64_t> ind; // 0/1 to track [pmin(y) > pb] fenwick_tree phi_sum; // partial sums PhiBlock ...
qwr's user avatar
  • 11.5k
0 votes
1 answer
85 views

std::string and default move constructor causing heap corruption

While refactoring some code, I've run into an issue with heap corruption. namespace GPU { struct ShaderStage { public: ShaderStage(ShaderStageType, const Path&); ...
garlfin's user avatar
  • 11
6 votes
1 answer
311 views

Overloaded default constructor with initializer list constructor that is also a default constructor and list initialization

Consider the following example that compiles with clang but is rejected by edg, gcc and msvc. Demo #include <initializer_list> struct C { C(){} C(std::initializer_list<int> i = {...
Richard's user avatar
  • 47k
3 votes
1 answer
169 views

If I do not declare move constructor, the copy one is called, but if I delete the move constructor - compilation error - why?

struct X { X() = default; X(const X& src) { cout << "copy" << endl; } }; int main() { X x1; X x2(move(x1)); } Output: copy struct ...
Andrey Rubliov's user avatar
1 vote
1 answer
120 views

Trying to understand the different ways of initializing std::string

std::string str; std::string(str); std::string str = {}; Are they the same? If no then what's the difference? And when should I use each of them? New to C++ and trying to understand the different ...
Heca's user avatar
  • 39
2 votes
0 answers
110 views

Difference between deleting and not writing a constructor [duplicate]

The following code snippet #include <iostream> #include <vector> class IntegerContainer { public: IntegerContainer() { std::cout << "default" << std::...
Jan Hackenberg's user avatar
2 votes
3 answers
431 views

Why do we still need to implement 'noArgsConstructor' if Java gives a non-parameterized constructor by default?

In Spring boot if we are creating a POJO class and we end up creating only a parameterized constructor and not any default constructor then Java will throw errors, why does this happen if Java ...
Ananthu K Kumar's user avatar
1 vote
2 answers
154 views

What value to assign to a char* in default constructor c++?

I have a class String and I've made a field char* name, default, parameterized, copy constructor, destructor and overwritten operator =. My question is how my default constructor should look like for ...
zaraboy's user avatar
  • 21
1 vote
3 answers
195 views

Are these three default constructors equivalent in C++?

Consider the following code: #include <type_traits> template<typename T> struct A1 { T t; // implicitly-declared default constructor }; template<typename T> struct A2 { ...
xmllmx's user avatar
  • 44.5k
0 votes
1 answer
62 views

Using default constructor to set the object attribute to default value in C++

I created a class Event class Event { char m_event_desc[DESC_LENGTH + 1]; // description of the event unsigned int m_time; // time when the event starts unsigned int getHour(); ...
Himawari.Ksm's user avatar
-1 votes
1 answer
105 views

why default constructor is not used in value initialisation in c++ [duplicate]

c++ primer says : The default constructor is used automatically whenever an object is default or value initialized. Default initialization happens • When we define nonstatic variables (§ 2.2.1, p. 43)...
semicolon_missing's user avatar
0 votes
1 answer
80 views

Non-aggregate initialization

I need to implement an AutoDocs class that will contain information about the license plate number and driver's full name. It is necessary to implement the class with the following invariants: the ...
swecpp's user avatar
  • 13
-1 votes
2 answers
182 views

Could an implicit compiler created default constructor have more than a null body?

Could an implicit compiler created default constructor have more than a null body? According to IBM's website, the answer is: no. I have this project that's kind of stumping me though: This is where ...
Horace's user avatar
  • 163

15 30 50 per page
1
2 3 4 5
56