?
Solved

Template header... headache...

Posted on 2007-03-25
7
Medium Priority
?
264 Views
Last Modified: 2010-04-01
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
0
Comment
Question by:sakuya_su
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 10

Author Comment

by:sakuya_su
ID: 18787578
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
0
 
LVL 11

Expert Comment

by:DeepuAbrahamK
ID: 18787591
In your header file add these lines:

#ifndef _COMMON_LIST_H
#define _COMMON_LIST_H
....
your header file contents...
......
#endif
Best Regards,
DeepuAbrahamK
0
 
LVL 10

Author Comment

by:sakuya_su
ID: 18787608
There are 2 header files.

but anyway the problem is still there.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Assisted Solution

by:MacroLand
MacroLand earned 400 total points
ID: 18787680
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;

common_list.cpp;

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

Regards,
0
 
LVL 11

Expert Comment

by:DeepuAbrahamK
ID: 18787688
By the way did you include,

#include <list>
using namespace std;

Best Regards,
DeepuAbrahamK
0
 
LVL 11

Accepted Solution

by:
DeepuAbrahamK earned 1600 total points
ID: 18787694
Sorry I have overlooked :( never mind!! You have a seperate list class.
0
 
LVL 10

Author Comment

by:sakuya_su
ID: 18787699
lol I was very dumb >.> there was a <list> lib..... my types were overloaded...... thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question