C++题!高手解答!!!!!!!!!

[复制链接]
查看11 | 回复0 | 2009-6-11 06:44:05 | 显示全部楼层 |阅读模式
正解及分析部分见下面,运行结果你自己看了,我就不写了!#includeusing namespace std;class B1{public:B1 (int i){cout<<"constructing B1"<<i<<endl;};};class B2{public:B2 (int J){cout<<"constructing B2"<<J<<endl;};};class B3{public: B3(){ }B3 (int i){cout<<"constructing B3*"<<i<<endl;}; // 这里你要输出i,可是B3()没有提供参数,所以你要改下:B3 (int i)};class C:public B2,public B1,public B3{public:C (int a,int b,int c,int d):B1(a),mB2(d),mB1(c),B2(b){ /*因为之前我把B3()改成了B3 (int i),你的C类继承了B3,而C的构造函数里面却没有对 B3的初始化所以你要再给B3增加一个无参构造函数,见上面*/}private:B1 mB1;B2 mB2;B3 mB3;};//这里的;你肯定是在中文输入法下输入的,所以这边报错了int main(){C C1(1,2,3,4);return 0;}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行