多重继承中的问题
多重继承中,士兵类(Soldier)继承人类(Person),步兵类(Infantry)又继承士兵类,有三个test函数
void test1(Person p)
{
p.play();
}
void test2(Person &p)
{
p.play();
}
void test3(Person *p)
{
p.play();
}
实例化一个步兵类对象Infantry infantry;
然后调用函数test1(infantry);test2(infantry);test3(&infantry);
结果是这样的:
Person()
Soldier()
Infantry();
person--play()
jack
~person()
person--play()
jack
person--play()
jack
问题来了,为什么只执行一次Person的析构函数