Solved

Template header... headache...

Posted on 2007-03-25
7
261 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 100 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 400 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

726 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