C++调试控制台应用程序
C++ Debugging console app
我正在为学校开发一个调试控制台应用程序,在编译该程序时出错。
//DEBUG9-4
//This program creates Student objects
//and overloads < to compare student year in school
#include<iostream>
#include<string>
using namespace std;
class Student
{
private: //MISSING :
int stuID;
int year;
double gpa;
public:
Student(const int i, const int y, const double g); // NO VARIABLES DECLARED HERE
void showYear(); //MISSING THE CURLY BRACES
bool operator < (const Student);
};
Student::Student(const int i, const int y, const double g) // VARIABLES WERE NOT MATCHING
{
stuID = i;
year = i;
gpa = g; // VARIABLE g WAS POST TO BE THE "gpa" VARIABLE
}
void Student::showYear()
{
cout << year;
}
int Student::operator < (const Student otherStu)
{
bool less = false;
if (year < otherStu.year)
less = true;
return less;
}
int main()
{
Student a(111, 2, 3.50), b(222, 1, 3.00);
if(a < b)
{
a.showYear();
cout << " is less than ";
b.showYear();
}
else
{
a.showYear();
cout << " is not less than ";
b.showYear();
}
cout << endl;
return 0;
}
行:28错误:'int Student::operator<的原型;(const Student&otherStu("与课堂上的任何学生都不匹配。行:16错误:候选者为:bool学生::运算符<(学生(。
您想要这样实现它:
bool Student::operator < (const Student otherStu)
{
bool less = false;
if (year < otherStu.year)
less = true;
return less;
}
因为现在你的定义和声明不匹配,它们可能有不同的返回值。
或者你可以只做:
bool Student::operator < (const Student b)
{
return year < b.year ? true : false;
}
相关文章:
- C++控制台应用程序阻止退出
- 如何从 Win32 C++ 应用程序输出到父控制台窗口?
- 如何在 Win32 C++控制台应用程序中调用 UWP 类库
- 是否可以从控制台应用程序使用 C++/WinRT 创建窗口?
- 如何创建一个使用开源c项目的c++控制台应用程序
- c ++控制台应用程序,如何在控制台外部打印字符
- 像 CPP 中的控制台一样的应用程序
- 调试控制台 ChessEngine.exe "used"在另一个应用程序(国际象棋 GUI)中
- 将控制台应用程序直接输出到Visual Studio而不是外部Windows控制台中
- 如何在 Win32 控制台应用程序中注册不可见的窗口类?
- 如何将从控制台应用程序C++回调设置为C++ COM DLL
- 使用代码在 AWS 开发工具包C++控制台应用程序上设置凭证
- 直接输入控制台应用程序
- C++调试控制台应用程序
- C++控制台应用程序调用C++/CLI静态库
- 如何在控制台应用程序中添加滚动功能以显示更大的输入
- C++应用程序控制台未退出
- 如何使用VSCode调试C++应用程序控制台应用程序
- 用于调试消息的跨平台GUI应用程序控制台
- 自定义应用程序控制台和stderr