2011年5月24日

摘要: 当一个子类要定义自己的拷贝构造函数时,要记得调用基类的拷贝构造函数,不然的话,当调用子类的拷贝构造函数时,需要调用基类的构造函数,此时调用的是基类的默认构造函数,这样会产生不期望的后果。如:ClassBase{inti;Public:Base(intii):i(ii){};Base(const&Baseb):i(b.i){};Base():i(0){};}ClaeeChild:publicBase{Inti;Public:Child(intii):Base(ii),i(ii){};Child(const&c):Base(c),i(c.i){};//调用基类的拷贝构造函数} 阅读全文
posted @ 2011-05-24 21:10 也 阅读(246) 评论(0) 推荐(0) 编辑

导航