|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include<iostream>
- #include<cstdlib>
- #include<cstring>
- using namespace std;
- class Student
- {
- friend int operator-(int, Student);
- private:
- char Name[20];
- int Score;
- public:
- Student(char *N,int s)
- {
- strcpy(Name , N);
- Score = s;
- }
- bool operator>(Student b)
- {
- if (this->Score > b.Score)
- return true;
- else
- return false;
- }
- void ShowName(void) { cout << "名字=" << Name << endl; }
- void ShowName(void) { cout << "成绩=" << Score << endl; }
- };
- int operator-(int p, Student q)
- {
- return (p - q.Score);
- }
- int main()
- {
- Student x("yuanyangxin", 70);
- Student y("sasds", 80);
- x.ShowName();
-
- system("pause");
- return 0;
- }
复制代码
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(392,5): warning MSB8028: The intermediate directory (Debug\) contains files shared from another project (test.vcxproj). This can lead to incorrect clean and rebuild behavior.
1> 源.cpp
1>d:\workspace\vs2015\test\test\源.cpp(14): error C2146: 语法错误: 缺少“)”(在标识符“s”的前面)
1>d:\workspace\vs2015\test\test\源.cpp(14): error C3646: “s”: 未知重写说明符
1>d:\workspace\vs2015\test\test\源.cpp(14): error C2059: 语法错误:“)”
1>d:\workspace\vs2015\test\test\源.cpp(27): error C2535: “void Student::ShowName(void)”: 已经定义或声明成员函数
1> d:\workspace\vs2015\test\test\源.cpp(26): note: 参见“Student::ShowName”的声明
1>d:\workspace\vs2015\test\test\源.cpp(16): error C2065: “N”: 未声明的标识符
1>d:\workspace\vs2015\test\test\源.cpp(17): error C2065: “s”: 未声明的标识符
1>d:\workspace\vs2015\test\test\源.cpp(36): error C2661: “Student::Student”: 没有重载函数接受 2 个参数
1>d:\workspace\vs2015\test\test\源.cpp(37): error C2661: “Student::Student”: 没有重载函数接受 2 个参数
14行,中文逗号
重载ShowName函数,形参不能一模一样
|
|