I am making Player with an inventory of Item objects. in the process of adding and removing items to the Player i get an error that says multiple definitions of various functions from my Items List. Could someone please help me out with this?
Also, i am not sure if having the ItemList in a .h is the best idea. but that was how i was getting it to work before i had this error come up.
I did not think it would be beneficial to make an object out of the item list because I will only ever have 1 Item list so that is why i put it in the header file on its own.
What would be a better way of doing that? or is that ok?
If you'd like to view all of the files in the project, you can download them here(NOTE: i will probably take the temp site down when i get an answer):
https://sites.google.com/site/tempforquestioncplusplus/download
Thanks in advance for the help!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
ItemList.h
#include "Item.h"
Item ItemList[]{
//populated with ItemObjects
}
void PrintList({
//prints the inventory
}
main.cpp
#include <iostream>
#include "ItemList.h"
#include "Player.h"
int main(int argc, char *argv[]) {
Player player("Player1");
player.setPrimary(ItemList[4]);
player.setSecondary(ItemList[6]);
std::cout << "\n\n" << player.toString();
return 0;
}
Player.cpp
#include "ItemList.h"
void Player::addItem(Item AddItem){
for(int i = 0; i < InventoryLength; i++){
if(Inventory[i].getName() == ItemList[0].getName()){
Inventory[i] = AddItem;
}
}
}
void Player::removeItem(Item RemoveItem){
for(int i = 0; i < InventoryLength; i++){
if(Inventory[i].getName() == RemoveItem.getName()){
Inventory[i] = ItemList[0];
}
}
}
|
multiple definition of `ItemListByte()'
first defined here
multiple definition of `ItemListSize()'
first defined here
multiple definition of `PrintList()'
first defined here
multiple definition of `ItemList'
first defined here
bad reloc address 0x14 in section `.text$_ZN4ItemD1Ev