继承
#include <iostream>
using namespace std;
////////////////////////////////////////////////////////////////////////////////////////////////
class CBase {
public:
CBase() {cout << "CBase" << endl;}
// virtual ~CBase() {cout << "~CBase" << endl;} // Must be virtual func
~CBase() {cout << "~CBase" << endl;}
};
//----------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------
class CDerived : public CBase
{
public:
CDerived() {cout << "CDerived" << endl;}
virtual ~CDerived() {cout << "~CDerived" << endl;}
// ~CDerived() {cout << "~CDerived" << endl;}
};
//----------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------
void Func(CBase* pObj) {
delete pObj;
cout << "here" << endl;
}
int main() {
CDerived* pObj = new CDerived;
Func(pObj);
cout << "returned" << endl;
return 0;
}
为什么错了