Jump to content
  • Advertisement
Sign in to follow this  
Xorcist

Unresolved External Symbol Issue (Help)

This topic is 4818 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I had all my code in a single header file, and that compiled fine, but once I seperated the declaration from the implemetation things broke. I'm hoping someone here can tell me why, and how to fix it. I get these errors: Test.obj : error LNK2001: unresolved external symbol "public: __thiscall SL_List<int>::~SL_List<int>(void)" (??1?$SL_List@H@@QAE@XZ) Test.obj : error LNK2001: unresolved external symbol "public: __thiscall SL_List<int>::SL_List<int>(void)" (??0?$SL_List@H@@QAE@XZ) and my code is as follows: [SL_List.h]
#ifndef SL_LIST_H
#define SL_LIST_H

template<class Type>
struct Node
 {//Node
    Node<Type> *pNext;       // Pointer to the next Node
    Type Data;               // The data field
 };//Node

template<class Type>
class SL_List
 {//SL_List
   public:
     SL_List(void);          //Empty Constructor
     SL_List(const Type);    //Construct w/ Data
     ~SL_List(void);         //Destructor
     int Insert(const Type); //Insert a new element
     int Remove(void);       //Remove an existing element
   private:
     Node<Type> *pHead;      //Front front of the Linked List
     Node<Type> *pTail;      //End of the Linked List
  };//SL_List

#endif

[SL_List.cpp]
#include "SL_List.h"

template<class Type>
SL_List<Type>::SL_List(void)
 {
 }

template<class Type>
SL_List<Type>::SL_List(const Type)
 {
 }

template<class Type>
SL_List<Type>::~SL_List(void)
 {
 }

template<class Type>
int SL_List<Type>::Insert(const Type)
 {
 }

template<class Type>
int SL_List<Type>::Remove(void)
 {
 }

[Test.cpp]
#include "SL_List.h"

int main(void)
 {//Begin
    SL_List<int> MyList;
    return 0;
 }//End

Share this post


Link to post
Share on other sites
Advertisement
IIRC, you cannot seperate the implementations of templates. That's why it broke when you moved it and cannot fix it. I cannot remember the proper term its called when this happens.

Share this post


Link to post
Share on other sites
Unless your compiler supports the standard export keyword (which virtually no compiler does) templates must be defined in the same translation unit they where declared in. Basically means you need to define them all in the header, you can still define them outside the class but needs to be in the header. The closest you can get to that is to put the definitions in any old file then include the file at the bottom of the header its still not the same though.

Also if you wasn't aware the standard libary provides a list type which is implementated with a doubly linked list, there is also a standard library extension called slist which is a list implementated with a singly linked-list but it might not be supported on all compilers as its an extension not currently part of the standard.

Share this post


Link to post
Share on other sites
Only Comeau supports export. Most agree that it should be deleted from the standard in the next revision.

If you want to break up your files so the declarations are separate from the implementations you can have the implementations in a file and include it from the bottom of your .hh. I don't know anyone who does this.

Share this post


Link to post
Share on other sites
Quote:
Original post by Xorcist
[Test.cpp]

#include "SL_List.h"

int main(void)
{//Begin
SL_List<int> MyList;
return 0;
}//End



the declaration (and definition) of MyList in the above code requires that SL_List< int > be instantiated. the compiler must have the complete definition available at that point. the linker can not do this for us. so like the others said you can not separate the 'implementation' in the case of templates.

_ugly

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!