这是课本上讲构造函数一节的例题,照着抄了下来,不知道怎么改,深深的无力感,,
#include <iostream>
using namespace std;
class student
{
public:
student();
student(int m_id,char *m_name,float m_chinese,float m_english,float m_math);
void show();
private:
int id;
char *name;
float chinese,english,math;
};
student::student()
{
id=0;
chinese=english=math=0;
}
student(int m_id,char *m_name,float m_chinese,float m_english,float m_math) //
{
id=m_id;
name=m_name;
chinese=m_chinese;
english=m_english;
math=m_math;
}
student::show()
{
cout<<id<<endl;
cout<<chinese<<endl;
cout<<english<<endl;
cout<<math<<endl;
}
int main()
{
student s1;
student s2(1,90,80,70);
s1.show();
s2.show();
return 0;
}
1>------ 已启动生成: 项目: ConsoleApplication4, 配置: Debug Win32 ------
1> 源.cpp
1>cpp(19): error C2062: 意外的类型“int”
1>cpp(20): error C2143: 语法错误 : 缺少“;”(在“{”的前面)
1>cpp(20): error C2447: “{”: 缺少函数标题(是否是老式的形式表?)
1>cpp(28): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>cpp(28): error C2556: “int student::show(void)”: 重载函数与“void student::show(void)”只是在返回类型上不同
1>cpp(8) : 参见“student::show”的声明
1>cpp(28): error C2371: “student::show”: 重定义;不同的基类型
1>cpp(8) : 参见“student::show”的声明
1>cpp(37): error C2661: “student::student”: 没有重载函数接受 4 个参数
1>cpp(38): error C2264: “student::show”: 函数定义或声明中有错误;未调用函数
1>cpp(39): error C2264: “student::show”: 函数定义或声明中有错误;未调用函数
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========