在C++類中定義結構體的一些問題與解決
阿新 • • 發佈:2019-01-05
coding一段程式碼,發現在C++類中定義結構體有一些問題。
開始是這樣
class Student
{
private:
typedef struct
{
string _courseNumber;
double _score;
struct _courseList next;
}* _courseList;
private:
string _name;
string _student_ID;
string _student_grade;
_courseList _course;
public:
......
}
並沒有什麼問題,happy。。。
但在碼class的實現時,出現了問題:
沒想明白問題出在哪兒,詢問度娘,度孃的解釋是:
因為結構體定義中出現了
struct _courseList next;但 _courseList 這個名字卻是在下一行出現的,於是把編譯器弄懵了。改成這樣
class Student
{
private:
typedef struct _course_
{
<span style="white-space:pre"> </span>string _courseNumber;
double _score;
struct _course_ *next;
}* _courseList;
問題解決了。