面向对象程序设计(谭浩强版).ppt

面向对象程序设计(谭浩强版)要点

7.2.2 构造函数和析构函数(续) class N:public M { public: N() {n=0;} N(int i,int j,int k); ~N(); void Print(); private: int n; }; M::M(int i,int j,int k):M(i,j),n(k) { coutNs costructor called. nendl; } N::~N() { 7.2.2 构造函数和析构函数(续) coutNs destructor called. nendl; } void N::Print() { M::Print(); coutnendl; } void main() { N n1(5,6,7), n2(-2,-3,-4); n1.Print(); n2.Print(); } 输出: Ms constructor called.5,6 Ns constructor called.7 Ms constructor called.-2,-3 Ns constructor called.-4 5,6,7 -2,-3,-4 Ns destructor called.-4 Ms destructor cal

文档评论(0)

1亿VIP精品文档

相关文档