Jump to content
  • Advertisement
Sign in to follow this  
dave

How do i deal with this link error?

This topic is 5064 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

Hey all, I have this link error i dont know how to deal with. Error: ain.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall sList<float>::~sList<float>(void)" (??1?$sList@M@@UAE@XZ) main.obj : error LNK2001: unresolved external symbol "public: __thiscall sList<float>::sList<float>(void)" (??0?$sList@M@@QAE@XZ) main.cpp
#include "file.h"
#include "linked_list.h"

struct RECT
{
	int x, y, right, left;
};

int main (void)
{
	file newFile("C:\\Documents and Settings\\Dave\\Desktop\\star.bmp", "rb+");


	sList<RECT> recList;
	return 0;
}

list.h
#ifndef	_S_LINKED_LIST_
#define	_S_LINKED_LIST_

template <class TYPE>
class sList
{
public:
	sList();
	virtual ~sList();

private:

	// MEMBER DATA
	struct SLIST
	{
		TYPE structOfType;


		SLIST* next;
	} start, *node;

	// MEMBER METHODS
	inline void InitLinkedList();

};

#endif	_S_LINK

list.c
#include "linked_list.h"

template <class TYPE>
sList<TYPE>::sList()
{
	InitLinkedList();
}

template <class TYPE>
sList<TYPE>::~sList()
{
}

template <class TYPE>
void sList<TYPE>::InitLinkedList()
{
	start.next = NULL;
	node = &start;
}

Thanx for any help ace

Share this post


Link to post
Share on other sites
Advertisement
Unless your compiler supports the export keyword, and seeing as that looks like a MSVC error code, I'm willing to bet that yours doesn't, then you can't put the definition of a template in a separate source file without explicit instantiation for specific types. Without explicit instantiation, the complete definition of the template needs to be available at point of instantiation, which means, in effect, that the definition needs to go into the header. (Or an inline file of some sort, etc.)

For more details see these articles: "Export" Restrictions, Part 1 and "Export" Restrictions, Part 2.

And before petewood gets to this thread, I suppose I'll post this link for him. It's an article entitled "Instantiator: A (Mostly) Portable Framework for Separate Compilation of Templates"

Share this post


Link to post
Share on other sites
Template member functions need to be available inline at the point of usage; putting them in a separately compiled .cpp file doesn't work unless your compiler has template repository support (which neither MSVC nor GCC has).

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
And before petewood gets to this thread, I suppose I'll post this link for him. It's an article entitled "Instantiator: A (Mostly) Portable Framework for Separate Compilation of Templates"


Thanks (c:

Share this post


Link to post
Share on other sites
Yeah, that part of my stock answer used to read
Quote:

And since petewood no longer posts on the boards, I suppose I should post this link for him. It's an article entitled "Instantiator: A (Mostly) Portable Framework for Separate Compilation of Templates"


But now that you're back, maybe I should just take out that line and let you post it yourself. :P

Share this post


Link to post
Share on other sites
It's nice to be refered to. Makes me feel special. Thanks SiCrane.

I've been busy with my new 3 month old baby boy and also my dad died a month ago so things have been all over the place for me.

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!