2 yy15642766973 yy15642766973 于 2016.04.11 08:59 提问

关于C++的问题出了 好多错 看不懂错误 请求帮助,看晕了
c++

#include
class Stu
{
char *name;
double score;
public :
void Set(char *na,double s);
void Show();
~Stu();
friend int date(Stu &s1,Stu &s2,Stu &s3,Stu &s4,Stu &s5);
};
Stu::Set (char *na,double s)
{
score=s;
name=new char[strlen(na)+1];
strcpy(name,na);
}
Stu::Show ()
{
cout<<"name:"< }
Stu::~Stu ()
{
delete []name;
}
int date(Stu &s1,Stu &s2,Stu &s3,Stu &s4,Stu &s5);
{
int a[5]={s1.score,s2.score,s3.score,s4.score,s5.score};
int i,j,t;
for(i=0;i for(j=0;j if(a[j]>a[j+1])
{ t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
for(i=0;i<5;i++)
cout<<a[i]<<endl;

}
int main()
{
Stu s1,s2,s3,s4,s5;
s1.Set ("zhang",78);
s1.Show ();
s2.Set ("wang",89);
s2.Show ();
s3.Set ("zhao",92);
s3.Show ();
s4.Set ("li",65);
s4.Show ();
s5.Set ("chen",50);
s5.Show ();
date(s1,s2,s3,s4,s5);
return 0;
}
作业\score\one.cpp(28) : error C2447: missing function header (old-style formal list?)
C:\作业\score\one.cpp(44) : error C2264: 'Set' : error in function definition or declaration; function not called
C:\作业\score\one.cpp(45) : error C2264: 'Show' : error in function definition or declaration; function not called
C:\作业\score\one.cpp(46) : error C2264: 'Set' : error in function definition or declaration; function not called
C:\作业\score\one.cpp(47) : error C2264: 'Show' : error in function definition or declaration; function not called
C:\作业\score\one.cpp(48) : error C2264: 'Set' : error in function definition or declaration; function not called
C:\作业\score\one.cpp(49) : error C2264: 'Show' : error in function definition or declaration; function not called
C:\作业\score\one.cpp(50) : error C2264: 'Set' : error in function definition or declaration; function not called
C:\作业\score\one.cpp(51) : error C2264: 'Show' : error in function definition or declaration; function not called
C:\作业\score\one.cpp(52) : error C2264: 'Set' : error in function definition or declaration; function not called
C:\作业\score\one.cpp(53) : error C2264: 'Show' : error in function definition or declaration; function not called
执行 cl.exe 时出错.

4个回答

qq423399099
qq423399099   Ds   Rxr 2016.04.11 09:10
已采纳

Set和Show函数要加上函数的类型,比如void,改成:
void Stu::Set (char *na,double s) 和void Stu::Show ()
int date(Stu &s1,Stu &s2,Stu &s3,Stu &s4,Stu &s5)后面多了一个分号
Show函数里cout<<"name:"< }是什么鬼?要用cout的话包含头文件iostream,std::cout或者using namespace std;

u011210708
u011210708   2016.04.11 09:10

Set 和 Show 的 void呢?

java6218
java6218   2016.04.11 09:12

开头就不对啊。。。。
#include
using namespace std;

beifengche
beifengche   2016.04.11 10:13

头文件没有写 Set()和show()实现部分返回值类型没有写。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!