Linker + templatized function = poo

Started by
1 comment, last by Thunder_Hawk 19 years, 7 months ago
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?
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
Cartman's definition of sexual harrasement:"When you are trying to have intercourse with a lady friend, and some other guy comes up and tickles your balls from behind"(watch South Park, it rocks)
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.
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________

This topic is closed to new replies.

Advertisement