I am trying some new C++11 features on visual studio 11, started with the move constructor. I wrote a simple class called "MyClass" containing a move constructor:
class MyClass
{
public:
explicit MyClass( int aiCount )
: mpiSize( new int( aiCount ) ),
miSize2( aiCount)
{
}
MyClass( MyClass&& rcOther )
: mpiSize( rcOther.mpiSize )
, miSize2( *rcOther.mpiSize )
{
rcOther.mpiSize = 0;
rcOther.miSize2 = 0;
}
~MyClass()
{
delete mpiSize;
}
private:
int *mpiSize;
int miSize2;
};
I got there questions here:
- I assumed that the compiler would generate a move constructor for MyClass if I don't implement one - but it doesn't seems so?
- Is the implementation of the move constructor correct for MyClass?
- Is there a better way to implement the move constructor for MyClass?