Using a simple struct like
struct Foo { int i; };
I can create a new instance using the list of initializers; no need to write a constructor:
Foo foo { 314 };
If you now add a move constructor
struct Bar { int i; Bar(Bar&& other) { i = other.i; } };
The initializer no longer works, and I have to add a constructor too:
Bar(int i) : i(i) {}
I assume that this behavior is somewhat related to this answer (for user-defined move-constructor disables implicit copy-constructor? ), But more detailed information would be nice.
Edit: as indicated in the answers, this has to do with adding a constructor. Which, in turn, seems to create inconsistency if I add only the move operator:
struct Baz { int i; Baz& operator=(Baz&& other) { this->i = other.i; return *this; } };
The initializer works again, although with a slightly different syntax for "move" (yes, this is the actual default construct and the transfer destination, but the end result seems to be pretty much the same):
Baz baz{ 3141 }; Baz b; b = std::move(baz);
source share