2013-10-31 61 views
0

這是我的一個類的代碼不幸,我不斷收到一個錯誤,說'武器不是一種類型',我知道只是不確定這是什麼類型。如何糾正一個類型對象的錯誤

knight.h

1 #ifndef KNIGHT_H 
    2 #define KNIGHT_H 
    3 
    4 using namespace std; 
    5 
    6 class knight 
    7 { 
    8 private: 
    9  string name; 
10  int stamina; 
12  weapon weapon_in_hand(string weapon_type, int sr, int hc);*The problem is here* 
13 
14 public: 
15  void on_horse(); 
16  knight(string name, int stamina, string weapon_type, int sr,int hc); 
17  bool hit(); 
18  void unhorse_yourself(); 
19  bool are_you_exhausted(); 
20  void display(); 
21 }; 
22 #endif 
~                    
"knight.h" 22L, 418C           1,1   All 

,這它連接到

25 bool hit() 
26 { 
27 stamina=stamina-weapon_in_hand.stamina_required(); 
28 if(weapon_in_hand.did_you_hit()==true) 
29  return true; 
30 else 
31  return false; 
32 knight::knight(string n, int st, string weapon_type, int sr,int hc) 
33 :name(n), stamina(st), weapon_in_hand(weapon_type, sr, hc) 
34 { 
35 } 
+0

我想,你必須聲明武器是一個班級。 – sdasdadas

+0

我認爲'武器'也應該是一個班級? – admdrew

+0

如果您至少指定了您正在使用的編程語言(在標記中),將會有所幫助。儘管這很不言自明。 – Dan

回答

3

什麼這裏的錯誤是,你沒有申報的武器是什麼。

你有一個你忘了包含的頭文件嗎?

編譯器重新開始編寫每個.c/.cpp文件,因此請確保您包含#include頭文件以獲取要查找的類型定義。

3

未定義類型weapon。你必須在knight.h的頂部包含weapon.h(在使用之前)。如果這不存在,你必須創建這個類。

相關問題