我只想说我还在学习 C++,所以我从关于类和结构的模块开始,虽然我不明白所有内容,但我认为我说得对。编译器不断给我的错误是:
error: expected primary-expression before '.' token
这是代码:
#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% 确定它们是如何工作的。