no appropriate default constructor available

[复制链接]
查看11 | 回复2 | 2009-3-26 11:42:49 | 显示全部楼层 |阅读模式
#include
class B0
{
int nv;
public:

B0 (int n) {nv=n;cout<<"Member of B0"<<endl;}

void fun () {cout<<"fun of B0"<<endl;}
};
class B1:virtual public B0
{
int nv1;
public:

B1(int a):B0(a) {cout<<"Member of B1"<<endl;}
//B1(int a,int b):B0(a) {nv1=b; cout<<"Member of B1"<<endl;}
};
class B2:virtual public B0
{
int nv2;
public:

B2(int a):B0(a) {cout<<"Member of B2"<<endl;}

//B2(int a,int b):B0(a) {nv2=b; cout<<"Member of B2"<<endl;}
};
class D1:public B1,public B2
{
int nvd;
public:

D1(int a):Bo(a),B1(a),B2(a) {cout<<"Member of D1"<<endl;}

//B2(int a,int b,int c,int d):B0(a),B1(b),B2(c) {nvd=d; cout<<"Member of D1"<<endl;}

void fund() {cout<<"fund of D1"<<endl;}

//void fun() {cout<<"fun of D1"<<endl;}
};
void main ()
{ D1 d1(1);
d1.fund();
d1.fun();
}
程序运行到 :
D1(int a):Bo(a),B1(a),B2(a) {cout<<"Member of D1"<<endl;}
时出现错误 :
error C2512: 'B0::B0' : no appropriate default constructor available
该如何修改呢?

回复

使用道具 举报

千问 | 2009-3-26 11:42:49 | 显示全部楼层
一楼说的貌似有道理,把BO(O字母)改成B0(数字)试一下其实为了避免这种错误,应该在你的IDE中设置合适的字体,以区别零和字母0....
回复

使用道具 举报

千问 | 2009-3-26 11:42:49 | 显示全部楼层
D1(int a):B0(a),B1(a),B2(a) {cout<<"Member of D1"<<endl;} 你把B零写成B欧了...
回复

使用道具 举报

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

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行