所以我正在做一个有学生,地址和成绩单类的项目。类内成员初始化是否删除赋值运算符?
学生的构造函数如下:
Student::Student(int eid, string first, string last, Address campusAddress,
Transcript transcript)
{
setEID(eid);
setFirst(first);
setLast(last);
setAddress(campusAddress);
this->transcript = transcript; //error that says:
"Transcript::operator=(const Transcript&)" (declared implicitly) cannot be referenced
-- it is a deleted function.
}
所以我想的东西是错了我的成绩单构造。但是这些指令是将Transcript的默认构造函数清空,除了初始化变量courseCount为0.(该程序从文件中读取学生数据并将课程添加到学生成绩单中)。
我一直坚持一段时间任何人都可以帮助如何解决这个删除的函数错误?
下面是谈话的构造函数,如果你需要它:
Transcript::Transcript()
{
courseCount = 0;
}
编辑:成绩单原型
class Transcript
{
public:
//Constructor
Transcript();
double computeGPA() const;
void addCourse(const string& course, const int hours, const string& grade);
string getCourse(int index) const;
string getGradeEarned(const int index) const;
int getCourseCreditHours(const int index) const;
int count() const;
string toString() const;
private:
const int MAX_STUDENT_COUNT = 50;
string courseTaken[50];
int courseCreditHours[50];
string gradeEarned[50];
int courseCount = 0;
int computeTotalCreditHours() const;
int computeTotalQualityPoints() const;
};
您是否熟悉赋值运算符的概念?你能向我们展示成绩单的代码吗? – templatetypedef
也许你应该发布'Transcript'类的原型。 – cxxl
错误信息非常清楚,你需要实现“operator =”,顺便说一句,如果你使用C++ 11,你可以使用std :: move如果你实现了“&&移动拷贝构造函数” – kaitian521