Jump to content
  • Advertisement
Sign in to follow this  
sirSolarius

Linker + templatized function = poo

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

Here are the errors that I'm getting with my code:
Linking...
Oscar.obj : error LNK2019: unresolved external symbol "public: static class PacketFactory * __cdecl PacketFactory::GetInstance(void)" (?GetInstance@PacketFactory@@SAPAV1@XZ) referenced in function "public: __thiscall Oscar::Oscar(struct HWND__ *)" (??0Oscar@@QAE@PAUHWND__@@@Z)
Oscar.obj : error LNK2019: unresolved external symbol "public: void __thiscall PacketFactory::Destroy(void)" (?Destroy@PacketFactory@@QAEXXZ) referenced in function "public: __thiscall Oscar::~Oscar(void)" (??1Oscar@@QAE@XZ)
Oscar.obj : error LNK2019: unresolved external symbol "public: struct TLV * __thiscall PacketFactory::MakeTLV<unsigned long>(unsigned short,unsigned long)" (??$MakeTLV@K@PacketFactory@@QAEPAUTLV@@GK@Z) referenced in function "private: void __thiscall Oscar::Authorize(char *,char *,char *,int)" (?Authorize@Oscar@@AAEXPAD00H@Z)
Oscar.obj : error LNK2019: unresolved external symbol "public: struct TLV * __thiscall PacketFactory::MakeTLV<unsigned short>(unsigned short,unsigned short)" (??$MakeTLV@G@PacketFactory@@QAEPAUTLV@@GG@Z) referenced in function "private: void __thiscall Oscar::Authorize(char *,char *,char *,int)" (?Authorize@Oscar@@AAEXPAD00H@Z)
Oscar.obj : error LNK2019: unresolved external symbol "public: struct TLV * __thiscall PacketFactory::MakeTLVFromString(unsigned short,char *)" (?MakeTLVFromString@PacketFactory@@QAEPAUTLV@@GPAD@Z) referenced in function "private: void __thiscall Oscar::Authorize(char *,char *,char *,int)" (?Authorize@Oscar@@AAEXPAD00H@Z)
Oscar.obj : error LNK2019: unresolved external symbol "public: void __thiscall PacketFactory::AddTLVtoFLAP(struct FLAP *,struct TLV *)" (?AddTLVtoFLAP@PacketFactory@@QAEXPAUFLAP@@PAUTLV@@@Z) referenced in function "private: void __thiscall Oscar::Authorize(char *,char *,char *,int)" (?Authorize@Oscar@@AAEXPAD00H@Z)
Oscar.obj : error LNK2019: unresolved external symbol "public: struct TLV * __thiscall PacketFactory::MakeTLV<char *>(unsigned short,char *)" (??$MakeTLV@PAD@PacketFactory@@QAEPAUTLV@@GPAD@Z) referenced in function "private: void __thiscall Oscar::Authorize(char *,char *,char *,int)" (?Authorize@Oscar@@AAEXPAD00H@Z)
Oscar.obj : error LNK2019: unresolved external symbol "public: void __thiscall PacketFactory::AddToFLAP<unsigned long>(struct FLAP *,unsigned long)" (??$AddToFLAP@K@PacketFactory@@QAEXPAUFLAP@@K@Z) referenced in function "private: void __thiscall Oscar::Authorize(char *,char *,char *,int)" (?Authorize@Oscar@@AAEXPAD00H@Z)
Oscar.obj : error LNK2019: unresolved external symbol "private: void __thiscall Oscar::ParseError(struct FLAP *,class std::vector<struct TLV *,class std::allocator<struct TLV *> > *)" (?ParseError@Oscar@@AAEXPAUFLAP@@PAV?$vector@PAUTLV@@V?$allocator@PAUTLV@@@std@@@std@@@Z) referenced in function "private: bool __thiscall Oscar::ParseFLAP(struct FLAP *)" (?ParseFLAP@Oscar@@AAE_NPAUFLAP@@@Z)
Oscar.obj : error LNK2019: unresolved external symbol "public: class std::vector<struct TLV *,class std::allocator<struct TLV *> > * __thiscall PacketFactory::FLAPtoTLVs(struct FLAP *)" (?FLAPtoTLVs@PacketFactory@@QAEPAV?$vector@PAUTLV@@V?$allocator@PAUTLV@@@std@@@std@@PAUFLAP@@@Z) referenced in function "private: bool __thiscall Oscar::ParseFLAP(struct FLAP *)" (?ParseFLAP@Oscar@@AAE_NPAUFLAP@@@Z)
Debug/AIMFramework.exe : fatal error LNK1120: 10 unresolved externals

My code follows:
/////////////////////////////////////////////////////////////////////////////
// PACKETFACTORY.H
/////////////////////////////////////////////////////////////////////////////
//
// AUTHOR: ERIK GOLDMAN
// DATE: 9-11-04
// DESC: Creates FLAPs, SNACs and TLVs
// NOTES: 
// TOFIX: 
/////////////////////////////////////////////////////////////////////////////

#pragma once

#include "OscarDefines.h"
#include <vector>

struct FLAP
{
	BYTE channel;
	WORD sequenceNum;
	std::vector<BYTE> data;
};

struct SNAC
{
	WORD familyID, subTypeID;
	BYTE flags0, flags1;
	DWORD requestID;
	std::vector<BYTE> data;
};

struct TLV
{
	WORD type;
	std::vector<BYTE> value;
};

class PacketFactory
{
public:
	template <typename DataType>
	TLV *MakeTLV(WORD type, DataType d);
	
	TLV *MakeTLVFromString(WORD type, char *d);

	template <typename DataType>
	DataType ChangeEndianness(DataType d);

	template <typename DataType>
	void AddToFLAP(FLAP *f, DataType d);

	void AddTLVtoFLAP(FLAP *f, TLV *t);

	template <typename DataType>
	DataType ReadFromFLAP(FLAP *f, int &pos);

	std::vector<TLV*> *FLAPtoTLVs(FLAP *f);
	bool FLAPtoSNAC(FLAP *f, SNAC *s);

	static PacketFactory *GetInstance();
	void Destroy();

protected:
	PacketFactory(void);
	~PacketFactory(void);

	static PacketFactory *instance;
};

#include "PacketFactory.cpp"

The CPP #includes the .h, and Main has this:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "WindowManager.h"
#include "Oscar.h"

... code ...

What the heck is going on?

Share this post


Link to post
Share on other sites
Advertisement
u shuld have ur templatized function definitions in the same file as the declarations
u cant put the declaration in file.h and the definition in file.cpp
definition and declaration must be in file.h

Share this post


Link to post
Share on other sites
That is the key disadvantage to using templates: they must live in header files. The export keyword is meant to remedy this, but the current support of this feature is just shy of non-existant.

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!