Tekkaman

导航

 

什么时候会生成Copy Constructor?

 当无法应用 bitwise copy semantics时,就会生成copy constructor。以下4种情形,会生成copy constructor:

 1、内含“带 copy constructor"的成员对象时。此时要在copy constructor中插入调用成员对象copy constructor的代码。

 2、继承“带 copy constructor”的类时。此时要在copy constructor中插入调用成员对象copy constructor的代码。

 3、声明了 virtual 函数时。此时要在copy constructor中插入设置vptr的代码。

 4、声明了 virtual 继承时。此时要在copy constructor中插入设置vptr的代码。

 

posted on 2013-05-29 23:46  Tekkaman  阅读(261)  评论(0编辑  收藏  举报