#include "stdafx.h"
#include <iostream>
#include <list>
using namespace std;
struct A
{
protected:
int num;
public:
A()
{
cout<<"AAA"<<endl;
foo();
}
~A()
{
cout<<"AAA~~"<<endl;
}
int virtual foo()
{
cout<<"foo base"<<endl;
return 1;
}
};
struct B: A
{
public:
B()
{
cout<<"BBB"<<endl;
foo();
}
~B()
{
cout<<"BBB~~"<<endl;
}
int virtual foo()
{
cout<<"foo dera"<<endl;
return 1;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
A *p=new B;
cout<<"Test"<<endl;
cout<<p->foo()<<endl;
cout<<"Test"<<endl;
delete p;
return 1;
}
各种继承关系
最新推荐文章于 2024-01-12 15:34:35 发布