我试图在我的 player.cpp 中创建一个重载的构造函数,但它给了我一个错误,即没有重载函数“player:player”的实例与指定的类型匹配。
这是供参考的标题
#ifndef PLAYER_H
#define PLAYER_H
#include <string>
#include <iostream>
#include "Item.h"
using namespace std;
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();
};
#endif
这是.cpp
#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 ->inventory;
}
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;
this ->inventory = inventory;
}
这是我创建播放器对象的主要位置
DLinkedList<player> list;
DLinkedList<Item> inventory;
//creates and appends a few default players to the linked list
player player1 = player("Jeremy", 2, 4 ,95, 5, 4, 3, 2, inventory);
list.Append(player1);
我很确定这是错误的,因为我希望每个库存对每个玩家都是独一无二的。
这是与该问题相关的一些输出错误
c:\users\liam\desktop\ca2 liam\doublelinkedlistca2\doublelinkedlistca2\player.h(22): error C2143: syntax error : missing ';' before '<'
1>c:\users\liam\desktop\ca2 liam\doublelinkedlistca2\doublelinkedlistca2\player.h(22): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\liam\desktop\ca2 liam\doublelinkedlistca2\doublelinkedlistca2\player.h(22): error C2238: unexpected token(s) preceding ';'
1>c:\users\liam\desktop\ca2 liam\doublelinkedlistca2\doublelinkedlistca2\player.h(26): error C2061: syntax error : identifier 'DLinkedList'
1>c:\users\liam\desktop\ca2 liam\doublelinkedlistca2\doublelinkedlistca2\player.cpp(21): error C2039: 'inventory' : is not a member of 'player'
1> c:\users\liam\desktop\ca2 liam\doublelinkedlistca2\doublelinkedlistca2\player.h(10) : see declaration of 'player'
1>c:\users\liam\desktop\ca2 liam\doublelinkedlistca2\doublelinkedlistca2\player.cpp(24): error C2511: 'player::player(std::string,int,int,double,double,int,int,int,DLinkedList<Datatype>)' : overloaded member function not found in 'player'