//bintree.h
template<class T>
class bintree
{
private:
bin_node<T> *root;
public:
bintree(void);
void insert(const T);
void insert(const T, bin_node<T>*);
};
//bintree.cpp
#include "bintree.h"
template<typename T>
void bintree<T>::insert(const T input)
{
insert(input, root);
}
//tstatcontain is a non-template class-class
class tstatcontain
{
private:
string tname;
int wins, loses, games, champ, years_playing, playoffs;
public:
tstatcontain()
{tname="empty team name"; wins=0; loses=0; games=0; champ=0;
years_playing=0; playoffs=0;}
//constructor assumes an input of format from *.csv:
//tname, years_playing, games, wins, lose, playoffs, champ
tstatcontain(char* in);
void display(void);
string get_tname () { return tname; }
int get_wins () { return wins; }
int get_loses () { return loses; }
int get_games () { return games; }
int get_champ () { return champ; }
int get_yearsplaying () { return years_playing; }
int get_playoffs () { return playoffs; }
};
int main(int argc, char* argv)
{
ifstream idatabase("database.csv");
bintree<tstatcontain> teamstats;
//parse file and build tree
while(!idatabase.eof())
{
char inputline[256];
idatabase.getline(inputline, 256);
tstatcontain in(inputline);
teamstats.insert(in);
}
idatabase.close();
//some code to use tree here
return 0;
}
Hi all,
I have been writing this code for a project and everything seems to be going great as it compiles normally, but when the compiler begins to link everything I get an error: Release\obj\main.o:main.cpp:(.text+0x240)||undefined reference to `bintree<tstatcontain>::insert(tstatcontain)'|
The problem seem to lie in the implementation of the template class bintree but I dont know how to fix it. All my reference seems to point out that I have used the syntax for implementing template classes correctly. Is there anything else I should know in order to resolve this problem (why is this happening?)?
Thanks in advance. :)