您的位置:首页 > 其它

在构造函数/析构函数中能否调用虚函数?

2017-10-11 21:05 232 查看
classBase
{
public:
Base()
{
Fuction();
}

virtualvoidFuction()
{
cout<<"constructBase::Fuction"<<endl;
}

~Base()
{
desFuction();
}

virtualvoiddesFuction()
{
cout<<"destructBase::Fuction"<<endl;
}
};

classA:publicBase
{
public:
A()
{
Fuction();
}
~A()
{
desFuction();
}
virtualvoidFuction()
{
cout<<"constructA::Fuction"<<endl;
}
virtualvoiddesFuction()
{
cout<<"destructrA::Fuction"<<endl;
}
};

inttest()
{
Aa;
return0;
}


输出结果:

cout<<"constructBase::Fuction"<<endl;

cout<<"constructA::Fuction"<<endl;

cout<<"destructrA::Fuction"<<endl;

cout<<"destructBase::Fuction"<<endl;


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: