我不知道该怎么称呼我遇到的问题,但它一直困扰着我半个小时,现在试图解决它。我正在尝试将 Item 类作为库存传递给播放器类中的链表,但我在这样做时遇到了麻烦。player.cpp 无法识别 Item 类并将其称为“class DLinkedList<>”。我也不确定将链表添加到构造函数本身。
#include "player.h"
#include "Item.h"
#include "DLinkedList.h"
// ----------------------------------------------------------------
// Name: Constructor
// Description: Constructor
// Arguments:
// Return Value: None.
// ----------------------------------------------------------------
player::player(){
this ->name = "default";
this ->lvl = 99;
this ->exp = 99;
this ->maxweight = 99;
this ->currentweight = 99;
this ->health = 99;
this ->strenght = 99;
this ->defence = 99;
this -> //trying to add linked list here
}
player::player( string name, int level, int experience, double maxweight, double currentweight, int health, int strenght, int defence, DLinkedList<Item> inventory){
this ->name = name;
this ->lvl = lvl;
this ->exp = exp;
this ->maxweight = maxweight;
this ->currentweight = currentweight;
this ->health = health;
this ->strenght = strenght;
this ->defence = defence;
}
这里也是播放器标题
class player{
public:
//Data members
string name;
int lvl;
int exp;
double maxweight;
double currentweight;
int health;
int strenght;
int defence;
DLinkedList<Item> inventory;
//Constructor
player();
player(string name, int level, int experience, double maxweight, double currentweight, int health, int strenght, int defence, DLinkedList<Item> inventory);
~player();