Thursday, 19 September 2013

Default value initialization in a default move constructor

Default value initialization in a default move constructor

Given an example class:
class Foo
{
int x = 0;
...
public:
Foo (Foo &&) = default;
...
};
The default constructor will be implemented as:
Foo::Foo () : x (0), ... { ... }
Is the default initialization value honoured by the explicitly defaulted
move constructor? i.e., implemented as:
Foo::Foo (Foo && f) : x (f.x), ... { f.x = 0; ... }
Furthermore, if the move constructor is implemented (not defaulted), and x
is omitted from the initializer list, will it still be initialized to the
default (0) value? i.e.,
Foo::Foo (Foo && f) : ... { f.x = 0; } // will (x) be (0) ?

No comments:

Post a Comment