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.

template <class ListDat>
class list
            struct item
                  ListDat data;
                  item *next;

            item *node;
            item *current;
            void add(ListDat data);
            bool first_item(ListDat &data);
            bool next_item(ListDat &data);
            //bool reverse();
            bool isEmpty();
            int len();
            void rewind();

class BigNumber
            list<int> digits;


            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"


#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
LVL 10
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

Deepu AbrahamConnect With a Mentor R & D Engineering ManagerCommented:
Sorry I have overlooked :( never mind!! You have a seperate list class.
sakuya_suAuthor Commented:
to elaborate further, these are the errors:

Error      1      error LNK2019: unresolved external symbol "public: __thiscall list<int>::list<int>(void)" (??0?$list@H@@QAE@XZ) referenced in function "public: __thiscall BigNumber::BigNumber(void)" (??0BigNumber@@QAE@XZ)      BigNumber.obj

Error      2      error LNK2019: unresolved external symbol "public: __thiscall list<int>::~list<int>(void)" (??1?$list@H@@QAE@XZ) referenced in function "public: __thiscall BigNumber::~BigNumber(void)" (??1BigNumber@@QAE@XZ)      BigNumber.obj


basically any of the functions in that template class
Deepu AbrahamR & D Engineering ManagerCommented:
In your header file add these lines:

#ifndef _COMMON_LIST_H
#define _COMMON_LIST_H
your header file contents...
Best Regards,
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

sakuya_suAuthor Commented:
There are 2 header files.

but anyway the problem is still there.
MacroLandConnect With a Mentor Commented:
in BigNumber.h include common_list.h;
in BigNumber.cpp include BigNumber.h
in main function just include #include "BigNumber.h";

besides always use header guards as DeepAbrahamK suggested.

And I think you separate common_list.h and common_list.cpp

so in your common_list.cpp file so your functions should be like;


template <class ListDat> list<ListDat>::list()

Deepu AbrahamR & D Engineering ManagerCommented:
By the way did you include,

#include <list>
using namespace std;

Best Regards,
sakuya_suAuthor Commented:
lol I was very dumb >.> there was a <list> lib..... my types were overloaded...... thanks
All Courses

From novice to tech pro — start learning today.