Reputation: 77
I'm trying to create an overloaded constructor inside my player.cpp but it's giving me the error that there is no instance of overloaded function "player:player" matches the specified type.
Here is the header for reference
#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
and here is the .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;
}
Here is the main where I create the player object
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);
I am pretty sure that is wrong however since I want each inventory to be unique to each player.
Here is some of the output errors related to the issue
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'
Upvotes: 0
Views: 957
Reputation: 51920
You forgot to:
#include "DLinkedList.h"
in player.h. That causes an error in line 22:
DLinkedList<Item> inventory;
because DLinkedList
is unknown to the compiler.
Upvotes: 4