关于虚函数,在多态当中,一定要将基类的析构函数设置为虚函数并将其实现,只有这样,才能够达到按对象构造的逆序来析构对象;否则,析构的时候,只会析构基类的那一部分,那么派生类那一部分就无法成功析构了。当指向派生类对象的指针被删除的时候,如果析构函数是虚函数(它应该如此),那么就会正确的操作——调用派生类... Read More
posted @ 2013-05-09 23:05
findumars
Views(811)
Comments(0)
Diggs(0)
#include "stdafx.h"#include using namespace std;class shape{public: shape(){}; void draw() { coutdraw(); s = new round(); s-... Read More
posted @ 2013-05-09 22:47
findumars
Views(275)
Comments(0)
Diggs(0)

浙公网安备 33010602011771号