【发布时间】:2016-03-15 14:17:25
【问题描述】:
我尝试通过以下方式实现学生的基本课程:
class Student
{
public:
Student(std::string name_ , int const id_);
virtual ~Student();
void addGrade(int const grade2add);
void print();
private:
std::string name;
int const id;
std::vector<int> grades;
int cost maxGrade;
};
构造函数:
Student::Student(std::string name_, int const id_): name(name_), id(id_)
{
if (name.size()>=20)
{
cout<<"Name should be less than 20 chars"<<endl;
}
if (id.size()!=5)
{
cout<<"Id should be 5 nums"<<endl;
}
}
主要内容: 使用命名空间标准;
int main()
{
cout << "Hello School!" << endl;
Student sarit_student("Sarit Rotshild",12345);
return 0;
}
*包括所有相关的库和文件。 我收到以下错误: 错误:未初始化的成员 'Student::maxGrade' 与 'const' 类型 'const int' [-fpermissive]
【问题讨论】:
-
您的错误信息与您拥有的代码不匹配。
Student::maxGrade是什么,这个错误来自源代码中的哪一行? -
在您的构造函数中,您是否应该检查
id是否有五位数字?那么这不是这样做的方法(你不能在像int这样的简单类型上调用“成员函数”)。进行检查也有点晚了,特别是如果您除了打印消息之外什么都不做。 -
你应该把问题所在的洞码放上去。
-
@NathanOliver- 在构造函数的行中- Student::Student(std::string name_, int const id_): name(name_), id(id_)