2016-05-21 44 views
0

我在我的頭文件中收到了一些我似乎無法解決的錯誤。它們似乎都在使用class Tutor類型。關於單一類型的頭文件中的各種錯誤

這裏是我的代碼:

#pragma once 
 
#include "Pupil.h" 
 
#include "Tutor.h" 
 
class Class 
 
{ 
 
\t char name; 
 
\t int num; 
 
\t Pupil** pupils; 
 
\t int pupil_amount; 
 
\t Tutor* tutor; 
 
public: 
 
\t Class(); 
 
\t Class(char, int); 
 
\t ~Class(); 
 
\t bool Add_Pupil(Pupil* p); 
 
\t Pupil* Get_Pupil(int ind); 
 
\t int Get_Amount()const { return pupil_amount; }//get the amount of pupils 
 
\t int Get_Num()const { return num; }//get the name of the class 
 
\t Tutor* Get_Tutor()const { return tutor; } //return a pointer to the tutor 
 
\t void Add_Tutor(Tutor* t) { tutor = t; }//set a tutor recieved as a pointer 
 
\t char Get_Name()const { return name; } 
 

 
};

這些都是錯誤的:

enter image description here

我解決它通過聲明類的 「家庭教師」 作爲一個朋友,但隨後我的教授告訴我不要使用朋友聲明。 我試圖將功能移到.cpp文件中,但沒有運氣。

有沒有什麼辦法可以解決這個問題,而不使用朋友?

回答

1

發生此錯誤是因爲編譯器在編譯'Class'時沒有'Tutor'類的聲明。檢查'Tutor.h'是否包含Tutor類的聲明。

+0

我剛添加了一個聲明,它的工作。所以首先謝謝你! 它可能沒有被宣佈,因爲教師從另一個班級繼承? – mrpink121

+0

它不取決於它是否被繼承。該類應在第一次使用之前,在相同的頭文件或包含的內容中聲明。 – CodeFuller