I'm working on something personal as an exercise with classes. As background, I basically just want to make a class for players of a board game, to keep track of the order of their turns based on some simple calculations using their stats.
My Player class includes this constructor line:
Player(string name, int Dex, int Mod, int Lvl, int diceRoll);
Its private data is as follows:
int Dex, Mod, Lvl;
string name;
I have the following in my main function, and have included the iostream and string libraries.
int rollD; //Will be input by the user
Player Derek("Derek", 2, 0, 6, rollD);
//... etc.
The error that the compiler throws is precisely this:
Initiative.obj : error LNK2019: unresolved external symbol "public: __thiscall Player::Player(class std::basic_string,class std::allocator >,int,int,int,int)" (??0Player@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@HHHH@Z) referenced in function _main
I am using Visual Studio 2012. From what I can tell, it's taking issue with the syntax of my constructor call, though I believe it to be correct.
Can anyone help me out? I've looked through the other threads with "External Symbol" errors, but I don't appear to have done the things that caused their errors, as my code is very simple.
Thanks!
EDIT: New error. I've changed the name of my private members in the class to be more readily identifiable (mDex, for example). So I have the following:
Player::Player(string name, int Dex, int Mod, int Lvl, int diceRoll) {
mName = name;
mDex = Dex;
mMod = Mod;
mLvl = Lvl;
}
Now my error is in the string name parameter. It seems to define name as the type, not the variable, and says I am not allowed to use type name.
EDIT 2: Full code below.
#include <iostream>
#include <string>
using namespace std;
class Player {
public:
Player(string name, int Dex, int Mod, int Lvl, int diceRoll);
int calcInitiative(int Dex, int Mod, int Lvl);
int sortInitiative(int Init);
int diceRoll;
private:
int mDex, mMod, mLvl;
string mName;
};
int main() {
int rollD; //To be given by the user later.
Player::Player(string name, int Dex, int Mod, int Lvl, int diceRoll) {
mName(name), mDex(Dex), mMod(Mod), mLvl(Lvl);
}
Player Derek("Derek", 2, 0, 6, rollD);
return 0;
}