Class A, {}.
Class B {};
Class C: public A, public {B};
Void main ()
{
C * C=new C;
B * B=static_cast & lt; B * & gt; (c);
The delete b;
}
Compile-time error, if you will be the order of A and B when inheritance after switch can run normally, and, if is to inherit A, B C is inherited, can run normally, why is this so, strives for the great god,
CodePudding user response:
When multiple inheritance first compare the main,CodePudding user response:
When multiple integration of several base class in memory location is not the same, one of the first in the front, address the same as the derived classes, so when the delete will not go wrongCodePudding user response:
On the second floor, can you point in detail, it is not clearCodePudding user response:
Take a look at this link, should speak more detailhttp://blog.csdn.net/dongfengsun/article/details/1476362
CodePudding user response:
Dataxdata, thanks for sharing!CodePudding user response:
C * C=new C;B * B=static_cast & lt; B * & gt; (c);//this point is not equal to c to b, "probably" will have an offset, which is connected with the compiler,
The delete b;//cause the abnormal, moreover, generally don't use, unless for virtual destructor,
Multiple inheritance is very trouble, I also don't understand,
CodePudding user response:
B * B=new C;
The delete b;
CodePudding user response:
Pointed out this is because b c b type in the way a \ b refers to the first address is not c, so there is something wrong with the release,CodePudding user response: