C++ の次のコードに関連する 2 つの質問があります。
class Base
{
public:
virtual bool deleteMe()
{
delete this;
return true;
}
};
class Derived: public Base
{
public:
void setBCO(const BigCustomObject& t_BCO)
{ m_BCO=t_BCO;}
BigCustomObject m_BCO;
};
int main()
{
Derived *pDerived = new Derived();
//insertint the "BigCustomObject" by new or local copy makes no difference, or?
//Because the "setBCO(){m_BCO=t_BCO;}" calls the copy operator anyway, or?
pDerived->setBCO( ... );
bool checkDel = pDerived->deleteMe();
//bool checkDel = ((Base*)pDerived)->deleteMe(); //Does this make any difference?
std::cout<<checkDel;
}
1.) deleteMe() 関数が自身のオブジェクトを削除した後に値を返す可能性があるのはどうしてですか?
2.) ベース オブジェクトのみを削除すると、派生オブジェクトの「BigCustomObject」はどうなりますか?
ありがとうございました。