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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…