首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

错在哪?该如何解决

2012-02-06 
错在哪?#includeiostream#includestring.hclass Hard{protected:char bodyname[20]public:Hard(char*

错在哪?
#include<iostream>
#include<string.h>
class Hard
{
protected:
char bodyname[20];
public:
Hard(char* bdnm)
{
cout<<"con H\n";
strcpy(bodyname,bdnm);}
Hard(Hard & abody){
cout<<"copy H\n";
strcpy(bodyname,abody.bodyname);
}
class Soft{
protected:
char os[10];
char lang[15];
public:
Soft(char * o,char *lg){
cout<<"conF\n";
strcpy(os,o);
strcpy(lang,lg);
}
class Sytem:public Hard,public Soft{
char owner[10];
public:
System(char * ow,char * bn,char * o,char * lg):Hard(bn),Soft(o,lg)
{
cout<<"con S\n";
strcpy(owner,ow);
}
System(Hard abody,Soft asoft,char * ow):Hard(abody),Soft(asoft){
cout<<"copy S\n";
strpy(owner,ow);}
void print(){
cout<<"owner:"<<owner;
cout<<";\n hard:"<<bodyname;
cout<<"\n soft:"<<","<<lang<<endl;
}
};
void main(){
System bsystem("Wang","IBM PC","PC DOS","True BASEC");
bsystem.print();
cout<<"OK! \n";
Hard abody("AST 386 sx/16");
Soft asoft("PC DOS","Borland C++");
System asystem("AST 386/16",asoft,"Zhang");
asystem.print();
}
//输出结果应该是
con H
con F
con S 
owner:Wang;
hard:IBM PC;
soft: ;C DOS,True BASIC
Ok!
con H
con F
con F
CON H
copy H
copy F
copy S
owner:Zhang;
hard:AST 386sx/16;
soft:PC DOS,Borland C++



















[解决办法]
你错在hard和soft的类的括号少了。。。。
[解决办法]
加上后运行正常
con H
conF
con S
owner:Wang;
 hard:IBM PC
 soft:,True BASEC
OK!
con H
conF
con H
copy H
copy S
owner:Zhang;
 hard:AST 386/16
 soft:,Borland C++
Press any key to continue

热点排行