我试着制作GradeBook
类,代表一门课程的成绩册。它具有存储课程名称的私有成员变量。类设置成员并获取课程名称,同时还显示欢迎消息。由于我是C++
的初学者,我遇到了以下错误:
Incomplete type is not allowed
- 下面是我正在编写的源代码:
#include<iostream>
#include<string>
using namespace std;
class GradeBook; // GradeBook class definition
{
public:
// constructor initializes courseName
GradeBook(string name)
{
setCourseName(name);
}
void setCourseName(string name)
{
courseName = name;
}
string getCourseName()
{
return courseName;
}
void displayMessage()
{
cout << "Welcome to the grade book for\n" << getCourseName() << "!" << endl;
}
private:
string courseName;
};
int main()
{
GradeBook gradeBook1("CS101 Introduction to C++ Programming");
GradeBook gradeBook2("Visual C++ introduction");
cout << "gradeBook1 created for course: " << gradeBook1.getCourseName()
<< "\ngradeBook2 created for course: " << gradeBook2.getCourseName()
<< endl;
return 0;
}
- 预期成果:
gradeBook1 created for course: CS101 Introduction to C++ Programming
gradeBook2 created for course: Visual C++ introduction
1条答案
按热度按时间5cnsuln71#
删除
class Gradebook
之后的;
,一切都应该正常。