// 親クラス
class Base{
public:
Base(){
cout << "Base::Base()" << endl;
}
~Base(){
cout << "Base::~Base()" << endl;
}
};
// 子クラス
class Deriv : public Base{
public:
Deriv(){
cout << "Deriv::Deriv()" << endl;
}
~Deriv(){
cout << "Deriv::~Deriv()" << endl;
}
};
void main(){
{
Deriv deriv;
}
cout << endl;
Base* pBase;
Deriv* pDeriv;
pBase = new Base();
delete pBase;
cout << endl;
pBase = new Deriv();
delete pBase;
cout << endl;
pDeriv = new Deriv();
delete pDeriv;
}
|
// 親クラス
class Base{
public:
Base(){
cout << "Base::Base()" << endl;
}
virtual ~Base(){
cout << "Base::~Base()" << endl;
}
};
// 子クラス
class Deriv : public Base{
public:
Deriv(){
cout << "Deriv::Deriv()" << endl;
}
virtual ~Deriv(){
cout << "Deriv::~Deriv()" << endl;
}
};
void main(){
{
Deriv deriv;
}
cout << endl;
Base* pBase;
Deriv* pDeriv;
pBase = new Base();
delete pBase;
cout << endl;
pBase = new Deriv();
delete pBase;
cout << endl;
pDeriv = new Deriv();
delete pDeriv;
}
|