照着课本上抄的,还有错误提示,不知道怎么改

王小c 2016-04-19 11:06:24


这是课本上讲构造函数一节的例题,照着抄了下来,不知道怎么改,深深的无力感,,

#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 个 ==========
...全文
103 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
王小c 2016-04-19
  • 打赏
  • 举报
回复
谢谢你,我知道了
  • 打赏
  • 举报
回复
student::student(int m_id,char *m_name,float m_chinese,float m_english,float m_math) // void student::show() student s2(1,"aaa", 90,80,70);

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧