多态 和 virual 析构的关系

namespace B { class CBase { public: CBase() { printf("+/n"); } virtual ~CBase() //virtual 加不加 打印结果不一样哦 { printf("-/n"); } protected: private: }; class CChild:public CBase { public: CChild() { printf("+/n"); } ~CChild() { printf("-/n"); } protected: private: }; } //调用 B::CBase *base = new B::CChild; delete base; //输出 + + - //加virual 有,否则无 -

你可能感兴趣的:(c++基础,class)