0

I know what this error is, and what it means, but for the life of me, I cant find the problem. (I'm working on a game which allows for the crafting of modular equipment, and that's where the breakdown is happening.)

to the best of my knowledge I have:

-I've included all the #includes that I need.

-I've checked my functions to make sure they have definitions

-I've made sure everything is squared away with how the classes are communicating

here's some of the code(I have 21 item types right now, so I'm gonna just use a few pieces):

//this is just a piece of this function, but it's just the same thing all the way down. This is where the breakdown seems to be happening.

void Inventory::chooseItem(int tag)
{
switch (tag)
{

    //armor

case '1':
    addArmorBack(makeNewArmor1(holder.back()));
    break;

case '2':
    addArmorBreastplate(makeNewArmor2(holder.back()));
    break;

case '3':
    addArmorStraps(makeNewArmor3(holder.back()));
    break;

//The relevant data holders in the private area of the .h:

vector<ItemPart> holder;
ArmorBack makeNewArmor1(ItemPart held);
ArmorBreastplate makeNewArmor2(ItemPart held);
ArmorStraps makeNewArmor3(ItemPart held);

//item part lists

 vector<ArmorBack> armorBackList;
 vector<ArmorBreastplate> armorBreastplateList;
 vector<ArmorStraps> armorStrapsList;

//This is a sample of the functions I'm using to add things to my list. It's the same function for each item.

void Inventory::addArmorBack(ArmorBack makeNew)
{
    string name;
    armorBackList.push_back(makeNew);
    name = makeNew.getName();
    addItem(name);
}

//the ItemPart class recieves data, then other functions direct the data to the right item part using the tag int:

class ItemPart
{
public:
ItemPart(int attack, int defense, int health, int experienceMult,     int tag, string name);

//setters
void setName();
//getters
int getDefense();
int getAttack();
int getHealth();
int getExperienceMult();
int getTag();
string getName();

private:
string _name;

int _defense;
int _attack;
int _health;
int _experienceMult;
int _tag;
};

//finally, the relevant item class recieves the data:

ArmorBack::ArmorBack(ItemPart crafted)
{

_attack = crafted.getAttack();
_defense = crafted.getDefense(); 
_health = crafted.getHealth();
_experienceMult = crafted.getExperienceMult();
_tag = crafted.getTag();
_name = crafted.getName();
}

edit: here's the error text. I have one of these for each item type I've implemented:

Error 37 error LNK2019: unresolved external symbol "private: class ArmorBack __thiscall Inventory::makeNewArmor1(class ItemPart)" (?makeNewArmor1@Inventory@@AAE?AVArmorBack@@VItemPart@@@Z) referenced in function "public: void __thiscall Inventory::chooseItem(int)" (?chooseItem@Inventory@@QAEXH@Z) C:\Users\Forresto\Documents\Visual Studio 2012\Projects\game challenge ascii\game challenge ascii\Inventory.obj game challenge ascii

forresto
  • 9
  • 1
  • 6
  • Although this has nothing to do with a linker error: `case '1':` Did you really mean '1' and not just 1 – drescherjm Jun 25 '16 at 23:10
  • 1
    Can you post the full text of the error message? Copy it from the output (Alt-2) window. – drescherjm Jun 25 '16 at 23:13
  • yes, each item part has a numbered tag, which I use to define which part the particular ItemPart usage is supposed to represent – forresto Jun 25 '16 at 23:14
  • @forresto: The error message should say that it couldn't find the implementation of some function or variable. Please add to the question the definition of that function or the place where you declare that variable. – Bill Lynch Jun 25 '16 at 23:14
  • sorry guys, I added the error text – forresto Jun 25 '16 at 23:15
  • The error is saying it can't find an implementation of `makeNewArmor1()`. I don't see this function defined in your code. Have you implemented this function? If so, where is it implemented relative to the code you have provided? – Andy Jun 25 '16 at 23:21
  • makeNewArmor1 is the ArmorBack I put in the data holders section. – forresto Jun 25 '16 at 23:25
  • could it be doing this if the class doesn't yet contain data? I only made it so I would have something to pass data into when something got made – forresto Jun 25 '16 at 23:26

1 Answers1

1

Just because you defined the

ArmorBack makeNewArmor1(ItemPart held);

class member function, in the header, doesn't mean that this member function will materialize out of thin air. It's only declared, and it must be defined in some translation unit (.cpp file). makeNewArmor1() is invoked from chooseItem(), so you have to define this member function somewhere.

Nothing you have posted indicates that this member function is defined anywhere. If it is defined in some translation unit, it is not getting linked properly. The link error you showed:

Error 37 error LNK2019: unresolved external symbol "private: class
ArmorBack __thiscall Inventory::makeNewArmor1(class ItemPart)"
(?makeNewArmor1@Inventory@@AAE?AVArmorBack@@VItemPart@@@Z) referenced
in function "public: void __thiscall Inventory::chooseItem(int)" 

is pretty much self-explanatory. It is true that C++ is notorious for confusing, incomprehensible compilation errors. But this isn't one of them. It pretty much tells you what the beef is: undefined symbol. It also tells you which symbol is not defined, and where it is referenced from. That's pretty much it. Not much else that needs to be known, here.

Either remove the call to makeNewArmor1(), or define this method in one of your translation units, or figure out whether the translation unit that defines this member function is not getting compiled and/or linked, correctly.

Ditto for the other link errors you showed.

Sam Varshavchik
  • 114,536
  • 5
  • 94
  • 148