constメンバー、constポインター、およびenumクラスメンバーを持つクラスがあります。
以下のサンプルコードに関する私の質問:
- 移動コンストラクターで「other」`の列挙型クラスメンバーを適切にnuliffyする方法(それに割り当てる値は?)
- 移動コンストラクタで「other」のconstポインタを無効にして、otherのデストラクタが構築中のオブジェクトのメモリを削除しないようにし、ポインタが有効になるようにするにはどうすればよいですか?
- 他のデストラクタが呼び出されないように、moveコンストラクタの「other」の定数メンバーを無効にする方法は?
enum class EnumClass
{
VALUE0, // this is zero
VALUE1
};
class MyClass
{
public:
MyClass() :
member(EnumClass::VALUE1),
x(10.f),
y(new int(4)) { }
MyClass(MyClass&& other) :
member(other.member),
x(other.x),
y(other.y)
{
// Can I be sure that this approach will nullify a "member" and avoid
// destructor call of other
other.member = EnumClass::VALUE0;
// Or shall I use this method?
other.member = static_cast<EnumClass>(0);
// ERROR how do I nullify "x" to avoid destructor call of other?
other.x = 0.f;
// ERROR the same here, delete is going to be called twice!
other.y = nullptr;
}
~MyClass()
{
delete y;
}
private:
EnumClass member;
const float x;
int* const y;
};