這是我的一個類的代碼不幸,我不斷收到一個錯誤,說'武器不是一種類型',我知道只是不確定這是什麼類型。如何糾正一個類型對象的錯誤
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 }
我想,你必須聲明武器是一個班級。 – sdasdadas
我認爲'武器'也應該是一個班級? – admdrew
如果您至少指定了您正在使用的編程語言(在標記中),將會有所幫助。儘管這很不言自明。 – Dan