[問題] C++的constructor
各位前輩好
最近再家自學C++
遇到一點小問題
#include<iostream>
#include<string>
using std::cout;
using std::endl;
using std::string;
class Gradebook
{
public:
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++");
GradeBook gradeBook2("CS102 Data Structure");
cout << "gradebook1 created for course: " << gradebook1.getCourseName()
<< "\ngradebook2 created for course: " << gradebook2.getCourseName();
return 0;
}
當我Compile的時候DEV C++說
ISO C++ forbids declaration of `GradeBook' with no type
可GradeBook是constructor不是不用type嗎?
煩請各位大大幫小的我解答
第一次發文請多包涵
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.62.56.236
推
02/07 15:42, , 1F
02/07 15:42, 1F
推
02/07 15:45, , 2F
02/07 15:45, 2F
推
02/07 16:02, , 3F
02/07 16:02, 3F
→
02/07 17:53, , 4F
02/07 17:53, 4F
→
02/07 18:32, , 5F
02/07 18:32, 5F
推
02/07 19:32, , 6F
02/07 19:32, 6F
推
02/07 23:18, , 7F
02/07 23:18, 7F
→
02/08 11:03, , 8F
02/08 11:03, 8F
推
02/08 13:58, , 9F
02/08 13:58, 9F
→
02/08 23:27, , 10F
02/08 23:27, 10F
→
02/08 23:27, , 11F
02/08 23:27, 11F
→
02/09 00:02, , 12F
02/09 00:02, 12F