我有两个与以下 C++ 代码相关的问题:
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”会发生什么情况?
谢谢你。