How to initialize an array member in a member initializer list

How can I do what I want to do (that is, initialize an array in a constructor (not assigning elements in the body)). Is it even possible? Yes. It’s using a struct that contains an array. You say you already know about that, but then I don’t understand the question. That way, you do initialize … Read more

Is it possible to prevent omission of aggregate initialization members?

Here is a trick which triggers a linker error if a required initializer is missing: struct init_required_t { template <class T> operator T() const; // Left undefined } static const init_required; Usage: struct Foo { int bar = init_required; }; int main() { Foo f; } Outcome: /tmp/ccxwN7Pn.o: In function `Foo::Foo()’: prog.cc:(.text._ZN3FooC2Ev[_ZN3FooC5Ev]+0x12): undefined reference to … Read more

Deleted default constructor. Objects can still be created… sometimes

When viewing things this way it is easy to say there is complete and utter chaos in the way an object is initialized. The big difference comes from the type of foo: if it is an aggregate type or not. It is an aggregate if it has: no user-provided constructors (a deleted or defaulted function … Read more

Narrowing conversions in C++0x. Is it just me, or does this sound like a breaking change?

I ran into this breaking change when I used GCC. The compiler printed an error for code like this: void foo(const unsigned long long &i) { unsigned int a[2] = {i & 0xFFFFFFFF, i >> 32}; } In function void foo(const long long unsigned int&): error: narrowing conversion of (((long long unsigned int)i) & 4294967295ull) … Read more

When is a private constructor not a private constructor?

The trick is in C++14 8.4.2/5 [dcl.fct.def.default]: … A function is user-provided if it is user-declared and not explicitly defaulted or deleted on its first declaration. … Which means that C‘s default constructor is actually not user-provided, because it was explicitly defaulted on its first declaration. As such, C has no user-provided constructors and is … Read more

Initializing a member array in constructor initializer

How can I do what I want to do (that is, initialize an array in a constructor (not assigning elements in the body)). Is it even possible? Yes. It’s using a struct that contains an array. You say you already know about that, but then I don’t understand the question. That way, you do initialize … Read more