sakuya_su
asked on
Template header... headache...
I have the following problem which I am confused about. So I would like some explanation if possible.
Now, I have 3 cpp files, 2 .h headers.
common_list.h:
template <class ListDat>
class list
{
private:
struct item
{
ListDat data;
item *next;
};
item *node;
item *current;
public:
list();
~list();
void add(ListDat data);
bool first_item(ListDat &data);
bool next_item(ListDat &data);
//bool reverse();
bool isEmpty();
int len();
void rewind();
};
BigNumber.h:
//-------------Prototypes- ---------- ---------- ----
class BigNumber
{
private:
list<int> digits;
public:
BigNumber();
~BigNumber();
void Read();
//void Add(list<int> first, list<int> second, list<int> &result);
void Add(BigNumber first, BigNumber second, BigNumber &result);
void Print();
};
ok, so Now in BigNumber.cpp, i have:
#include "common_list.h"
#include "BigNumber.h"
Main.cpp:
#include "common_list.h"
#include "BigNumber.h"
Here is the problem, whenever I tried to compile this, I get all these unresolved names error from the linker.. can anyone tell me what is wrong?
I have tried having all code in one cpp file, and it worked perfectly fine... its only when I have them seperated into their own files and written their own headers that this happens.
Thanks in advanced
Now, I have 3 cpp files, 2 .h headers.
common_list.h:
template <class ListDat>
class list
{
private:
struct item
{
ListDat data;
item *next;
};
item *node;
item *current;
public:
list();
~list();
void add(ListDat data);
bool first_item(ListDat &data);
bool next_item(ListDat &data);
//bool reverse();
bool isEmpty();
int len();
void rewind();
};
BigNumber.h:
//-------------Prototypes-
class BigNumber
{
private:
list<int> digits;
public:
BigNumber();
~BigNumber();
void Read();
//void Add(list<int> first, list<int> second, list<int> &result);
void Add(BigNumber first, BigNumber second, BigNumber &result);
void Print();
};
ok, so Now in BigNumber.cpp, i have:
#include "common_list.h"
#include "BigNumber.h"
Main.cpp:
#include "common_list.h"
#include "BigNumber.h"
Here is the problem, whenever I tried to compile this, I get all these unresolved names error from the linker.. can anyone tell me what is wrong?
I have tried having all code in one cpp file, and it worked perfectly fine... its only when I have them seperated into their own files and written their own headers that this happens.
Thanks in advanced
In your header file add these lines:
#ifndef _COMMON_LIST_H
#define _COMMON_LIST_H
....
your header file contents...
......
#endif
Best Regards,
DeepuAbrahamK
#ifndef _COMMON_LIST_H
#define _COMMON_LIST_H
....
your header file contents...
......
#endif
Best Regards,
DeepuAbrahamK
ASKER
There are 2 header files.
but anyway the problem is still there.
but anyway the problem is still there.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
By the way did you include,
#include <list>
using namespace std;
Best Regards,
DeepuAbrahamK
#include <list>
using namespace std;
Best Regards,
DeepuAbrahamK
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
lol I was very dumb >.> there was a <list> lib..... my types were overloaded...... thanks
ASKER
Error 1 error LNK2019: unresolved external symbol "public: __thiscall list<int>::list<int>(void)
Error 2 error LNK2019: unresolved external symbol "public: __thiscall list<int>::~list<int>(void
...
basically any of the functions in that template class