Solved

Template header... headache...

Posted on 2007-03-25
7
251 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
  • 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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 clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now