I've been making a text based RPG game in C++ to help me learn, but I'm getting Link errors I can't work out. The broken section is an attribute library - I'm trying to make the program as modular as possible, different functionalities (inventory, fighting, attributes etc) are all in different .cpp files.
The error is:
1>Hero.obj : error LNK2019: unresolved external symbol "public: __thiscall Attribute_Table::Attribute_Table(int)" (??0Attribute_Table@@QAE@H@Z) referenced in function _wmain
Main code below:
The problem I'm having is with these two lines:
These were written just as a basic test of the attribute source file - unfortunately it's failing already so I haven't gone on to write more detailed code.
attributes.h contains:
The definitions are here:
I haven't included all of this source file - the remaining functions are defined outside the class, but currently my issue is with the constructor. What I don't understand, is I'm able to create new variables of type Attribute fine - tested the Attribute class code and it seems to be working fine. I can't see any major difference between the constructors of class Attribute, and class Attribute_Table - yet Attribute_Table is giving a link error?
If I replace the two lines giving errors in main() with:
Attribute s;
The variable s of type Attribute is created without error - what's the difference between this and the Attribute_Table class? I'm confused. :lol:
The error is:
1>Hero.obj : error LNK2019: unresolved external symbol "public: __thiscall Attribute_Table::Attribute_Table(int)" (??0Attribute_Table@@QAE@H@Z) referenced in function _wmain
Main code below:
Code:
// Hero.cpp : Defines the entry point for the console application.
//
// This program is a hero attribute program for an RPG. Here, the player chooses their hero's attributes for their journey.
#include "stdafx.h"
#include "std_lib_facilities.h"
#include "attributes.h"
#include "common.h"
int _tmain(int argc, _TCHAR* argv[])
{
try
{
Attribute table table1; //error here
Attribute_Table table2 (30); //error here
keep_window_open();
}
catch (exception& e) {
cerr << "error: " << e.what() << '\n';
keep_window_open();
return 1;
}
catch (...) {
cerr << "Oops: unknown exception!\n";
keep_window_open();
return 2;
}
return 0;
}
The problem I'm having is with these two lines:
Attribute table table1; //error here
Attribute_Table table2 (30); //error here
These were written just as a basic test of the attribute source file - unfortunately it's failing already so I haven't gone on to write more detailed code.
attributes.h contains:
Code:
//Attribute system header files.
#include "stdafx.h"
#include "std_lib_facilities.h"
class Attribute {
public:
string name;
int points;
Attribute();
Attribute(string n);
Attribute(string n, int p);
};
class Attribute_Table {
// class containing table of attributes and interface.
public:
int get(string name); //return point value of attribute
int check(); //return remaining spending points
void increase(string name, int points); //increase point value of attribute
void decrease(string name, int points); //decrease point value of attribute
void define(string name); //define a new attribute
void define(string name, int points);
Attribute_Table();
Attribute_Table(int s);
private:
int spend; //remaining unused points.
vector<Attribute> table; //Vector of attributes
};
The definitions are here:
Code:
//Attribute structure
class Attribute {
public:
string name;
int points;
Attribute()
:name(), points() { }
Attribute(string n)
:name(n), points(0) { }
Attribute(string n, int p)
:name(n), points(p) { }
};
class Attribute_Table {
// class containing table of attributes and interface.
public:
int get(string name); //return point value of attribute
int check(); //return remaining spending points
void increase(string name, int points); //increase point value of attribute
void decrease(string name, int points); //decrease point value of attribute
void define(string name); //define a new attribute
void define(string name, int points);
Attribute_Table()
:spend(0), table() { }
Attribute_Table(int s)
:spend(s), table() { }
private:
int spend; //remaining unused points.
vector<Attribute> table; //Vector of attributes
};
I haven't included all of this source file - the remaining functions are defined outside the class, but currently my issue is with the constructor. What I don't understand, is I'm able to create new variables of type Attribute fine - tested the Attribute class code and it seems to be working fine. I can't see any major difference between the constructors of class Attribute, and class Attribute_Table - yet Attribute_Table is giving a link error?
If I replace the two lines giving errors in main() with:
Attribute s;
The variable s of type Attribute is created without error - what's the difference between this and the Attribute_Table class? I'm confused. :lol: