Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > "LNK2019 - Unresolved external Symbol" while using templates

Reply
Thread Tools

"LNK2019 - Unresolved external Symbol" while using templates

 
 
Mastadex
Guest
Posts: n/a
 
      09-30-2005
So here is my Code:

template <class T>
struct Nodes
{
T *Data; // The Image
char Name[50]; // The Name of the image

Nodes<T> *Prev;
Nodes<T> *Next;
};
typedef struct Nodes Node;


template <class T>
class List
{
Node *Current;

public:

List();
~List();

};

---------------------------------------------------

#include "List.h"

template <class T>
List<T>::List()
{

}

template <class T>
List<T>::~List()
{

}

================================================== ==

error LNK2019: unresolved external symbol "public: __thiscall
List<class Image>::~List<class Image>(void)"
(??1?$List@VImage@@@@QAE@XZ) referenced in function main...

Thats the error I get. Is this one of those subtle c++ bugs that I need
to work around? my main is quite simple, all it does is instanciate the
class. thats all:

List<int> foo;

Im completely confused.

 
Reply With Quote
 
 
 
 
mlimber
Guest
Posts: n/a
 
      09-30-2005
Mastadex wrote:
> So here is my Code:
>
> template <class T>
> struct Nodes
> {
> T *Data; // The Image
> char Name[50]; // The Name of the image
>
> Nodes<T> *Prev;
> Nodes<T> *Next;


There's no need for the <T> here. Nodes is fine.

> };
> typedef struct Nodes Node;


This is unnecessary in C++. You can drop this line and not change any
other code.

>
>
> template <class T>
> class List
> {
> Node *Current;
>
> public:
>
> List();
> ~List();
>
> };
>
> ---------------------------------------------------
>
> #include "List.h"
>
> template <class T>
> List<T>::List()
> {
>
> }
>
> template <class T>
> List<T>::~List()
> {
>
> }
>
> ================================================== ==
>
> error LNK2019: unresolved external symbol "public: __thiscall
> List<class Image>::~List<class Image>(void)"
> (??1?$List@VImage@@@@QAE@XZ) referenced in function main...
>
> Thats the error I get. Is this one of those subtle c++ bugs that I need
> to work around? my main is quite simple, all it does is instanciate the
> class. thats all:
>
> List<int> foo;
>
> Im completely confused.


You need to put the template function definitions in the header file.
See this FAQ:

http://www.parashift.com/c++-faq-lit....html#faq-35.7

Also, unless you're doing homework here, I'd suggest using std::list
instead of reinventing the wheel.

Cheers! --M

 
Reply With Quote
 
 
 
 
John Fullman
Guest
Posts: n/a
 
      09-30-2005
mlimber's got it exactly.
You need to put all templates in the header file.
There should be no .cpp file for templated classes.

 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      09-30-2005
John Fullman wrote:

> mlimber's got it exactly.


Got what exactly?



Brian

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
 
Reply With Quote
 
Mastadex
Guest
Posts: n/a
 
      09-30-2005
thanks guys.

im still a bit rusty with C++ after my vacation :/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
unresolved external symbol while linking dotyet C Programming 0 06-22-2007 06:41 PM
Using Py_InitModule3 -> [Linker Error] Unresolved external '_Py_InitModule4TraceRefs' iwl Python 2 12-09-2006 01:07 PM
unresolved external when using templates Shailesh Humbad C++ 7 05-04-2004 08:00 AM
unresolved external symbol/using an external dll Scott Allen C++ 8 05-02-2004 06:11 PM
Linking Error unresolved external symbo when using template and friend Yoon-Soo Lee C++ 5 01-02-2004 12:20 PM



Advertisments