博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
copy constructor
阅读量:4285 次
发布时间:2019-05-27

本文共 870 字,大约阅读时间需要 2 分钟。

#include
using namespace std;class A{public: A(){ cout <<"1";} A(const A &obj){ cout <<"2";}};class B: virtual A{public: B(){cout <<"3";} B(const B & obj){cout<<"4";}};class C: virtual A{public: C(){cout<<"5";} C(const C & obj){cout <<"6";}};class D:B,C{public: D(){cout<<"7";} D(const D & obj){cout <<"8";}};int main(){ D d1; D d(d1);}

Output will be 13571358 as 1357 (for D d1) and as 1358 (for D d(d1))......reason is that ......during inheritance we need to explicitly call copy constructor of base class otherwise only default constructor of base class is called. One more thing, as we are using virtual before base class, there will be only one copy of base class in multiple inheritance. And without virtual output will be......13157....&...13158 as (1315713158) respectively for each derived class object.

 

ref     question 14

转载地址:http://qesgi.baihongyu.com/

你可能感兴趣的文章
Java处理js输入特殊字符(如“+、@、¥”)
查看>>
Mysql注释
查看>>
MySQL(root用户)密码重置
查看>>
grant授权
查看>>
MySQL创建用户与授权方法
查看>>
MySql数据类型
查看>>
MySql简单sql使用
查看>>
"未能加载文件或程序集“MySql.Data, Version=6.9.3.0”或它的某一个依赖项。
查看>>
CodeFirst for MySql
查看>>
Code Frist for Mysql 实例
查看>>
Visual Studio 开源控件扩展 NuGet 常用命令及常用组件
查看>>
mysql局域网访问设置
查看>>
UEditor 编辑器跨域上传解决方法
查看>>
VisualSVN Server搭建SVN服务器
查看>>
AngularJs directive指令详解
查看>>
AngularJs directive-scope
查看>>
AngularJs directive-link实例
查看>>
Js实现Base64编码、解码
查看>>
AngularJs directive-scope双向绑定方法处理-实例2
查看>>
AngularJs Ajax分页控件
查看>>