Link to home
Start Free TrialLog in
Avatar of sakuya_su
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
Avatar of sakuya_su
sakuya_su

ASKER

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
Avatar of Deepu Abraham
In your header file add these lines:

#ifndef _COMMON_LIST_H
#define _COMMON_LIST_H
....
your header file contents...
......
#endif
Best Regards,
DeepuAbrahamK
There are 2 header files.

but anyway the problem is still there.
SOLUTION
Avatar of MacroLand
MacroLand
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
By the way did you include,

#include <list>
using namespace std;

Best Regards,
DeepuAbrahamK
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
lol I was very dumb >.> there was a <list> lib..... my types were overloaded...... thanks