Move constructor and assignment operator: why no default for derived classes?

Posted by doublep on Stack Overflow See other posts from Stack Overflow or by doublep
Published on 2010-04-22T20:39:49Z Indexed on 2010/04/22 20:43 UTC
Read the original article Hit count: 336

Why there is default move constructor or assignment operator not created for derived classes? To demonstrate what I mean; having this setup code:

#include <utility>

struct A
{
  A () { }
  A (A&&) { throw 0; }
  A& operator= (A&&) { throw 0; }
};

struct B : A
{ };

either of the following lines throws:

A  x (std::move (A ());
A  x;  x = A ();

but neither of the following does:

B  x (std::move (B ());
B  x;  x = B ();

In case it matters, I tested with GCC 4.4.

© Stack Overflow or respective owner

Related posts about c++

Related posts about c++0x