标题:运行结果
取消只看楼主
jjg
Rank: 2
等 级:论坛游民
帖 子:67
专家分:42
注 册:2009-8-19
结帖率:46.15%
已结贴  问题点数:20 回复次数:0 
运行结果
程序代码:
#include <iostream>
using namespace std;
class base
{
public:
base(int i)
{
x=i;
cout<<"constructor of base."<<endl;
}
~base(){cout<<"destructor of base."<<endl;}
viod show(){cout<<"x="<<x<<endl;}
private:
int x;
};
class derived:public base
{

public:
derived(int i):base(i),d(i){cout<<"constructor of derived."<<endl;}
private:
base d;
};
void main()
{
derived obj(5);
obj.show();
}




运行结果:
constructor of base.
constructor of base.//怎么有两遍?不懂
constructor of derived.
x=5
destructor of base.
destructor of base.
搜索更多相关主题的帖子: 运行结果 
2009-08-23 16:55



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-283514-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.242603 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved