我只想说我仍然在学习C++,所以我开始使用有关类和结构的模块,虽然我不明白所有的东西,但我认为我有点正确。编译器一直给我的错误是:C++错误 - 预期'。'之前的主表达式令牌|
错误:期望在'。'之前的主表达式。令牌|
这里是代码:
#include <iostream>
using namespace std;
class Exam{
private:
string module,venue,date;
int numberStudent;
public:
//constructors:
Exam(){
numberStudent = 0;
module,venue,date = "";
}
//accessors:
int getnumberStudent(){ return numberStudent; }
string getmodule(){ return module; }
string getvenue(){ return venue; }
string getdate(){ return date; }
};
int main()
{
cout << "Module in which examination is written"<< Exam.module;
cout << "Venue of examination : " << Exam.venue;
cout << "Number of Students : " << Exam.numberStudent;
cout << "Date of examination : " << Exam.date
<< endl;
return 0;
}
的问题要求用存取函数,但我不知道我为什么要使用存取器。
不是100%肯定它们是如何工作的。
请帮忙。
请格式化,并提供完整的示例代码。 –