So I have been getting an issue where when I am compiling my classes along with the main .cpp I am getting a linking error. I am not the most versed with C++ as this is my first year coding in this language. I am using VS Code for this as well.
My Team Class:
#ifndef TEAM_H
#define TEAM_H
#include "Player.h"
#include <vector>
using namespace std;
class Team{
public:
Team();
void setGold(int _Gold);
int getGold();
void changeGold(int _Gold);
void setIngredients(int _Ingredients);
int getIngredients();
void changeIngredients(int _Gold);
void setCookware(int _Cookware[3]);
void changeCookware(int _Cookware[3]);
void setArmor(int _Armor);
int getArmor();
void changeArmor(int _Armor);
void addWeapon(string _Name, string _Level);
string removeOneWeapon();
int getWeapons();
int getPlayers();
void setKey(bool _Key);
bool getKey();
void updateFull(int _Fullness);
static string weapons[5][2]; //First index is name, Second is level
//"NULL" and "NULL" = no weapon,
static int cookware[3];//0,1,2 index's equate to number of that type of cookware
vector<string> getTreasures();
int getTreasureSize();
static Player players[5];
private:
int gold;
int ingredients;
int armor;
bool key;
vector<string> treasures;
};
#endif
A function in another class that uses the weapons and Player array
void Game::startGame(){
string leaderName;
string playerOne, playerTwo, playerThree, playerFour;
monster1.readMonsterFile("monsters.txt");
cout << "Enter name of party leader:" << endl;
cin >> leaderName;
Team::players[0].setName(leaderName);
cout << "Enter the names of other party members:" << endl;
cin >> playerOne >> playerTwo >> playerThree >> playerFour;
Team::players[1].setName(playerOne);
Team::players[2].setName(playerTwo);
Team::players[3].setName(playerThree);
Team::players[4].setName(playerFour);
cout << "Welcome party leader " << leaderName << " and his/her companions " << playerOne << playerTwo << playerThree << playerFour << endl;
}
And then the error i am getting:
Williams-MacBook-Pro:Project3 William$ g++ -std=c++11 Player.cpp Team.cpp Monster.cpp Game.cpp main.cpp
Undefined symbols for architecture x86_64:
"Team::players", referenced from:
Team::getPlayers() in Team-b8a69d.o
Team::updateFull(int) in Team-b8a69d.o
Game::startGame() in Game-98f56e.o
Game::statusUpdate() in Game-98f56e.o
"Team::weapons", referenced from:
Team::Team() in Team-b8a69d.o
Team::getWeapons() in Team-b8a69d.o
Team::addWeapon(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in Team-b8a69d.o
Team::removeOneWeapon() in Team-b8a69d.o
Monster::attack(int, int, int) in Monster-7397ef.o
Game::statusUpdate() in Game-98f56e.o
"Team::cookware", referenced from:
Team::Team() in Team-b8a69d.o
Team::setCookware(int*) in Team-b8a69d.o
Team::changeCookware(int*) in Team-b8a69d.o
Game::statusUpdate() in Game-98f56e.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any help is much appreciated!
Aucun commentaire:
Enregistrer un commentaire