mefmef
mefmef

Reputation: 665

global template objects c++

i have a class

class ICIecHdlcSetup
{
 //some thing
};

to create a global access object i do this:

//in obj.cpp:
ICIecHdlcSetup obj_ICIecHdlcSetup(0x00,0x00,0x16,0x00,0x00,0xFF);

//in obj.hpp:
extern ICIecHdlcSetup obj_ICIecHdlcSetup;

now i have a template class:

template <class TValue>
class ICData
{
//some thing
};

but the same way would not work

//in obj.cpp:
ICData <uint8_t> temperture(7,64,41,0,0,255) ;

//in obj.hpp:
extern ICData <uint8_t> temperture ;

and make this error:

Error   10  error LNK2019: unresolved external symbol "public: void __thiscall ICData<unsigned char>::set_value(unsigned char)" (?set_value@?$ICData@E@@QAEXE@Z) referenced in function "void __cdecl object_instantiation(void)" (?object_instantiation@@YAXXZ)    E:\sv_repos\Test\Test\VS2010\Test\Test\Objects.obj  Test

thanks in advance.

Upvotes: 2

Views: 1678

Answers (1)

ssube
ssube

Reputation: 48267

The error given most likely means the function referenced simply doesn't exist, in general or in the current compilation unit.

Check to make sure it has been defined in the class body (in the header in the templated case) or is being imported properly (if coming from an external source, such as DLL or library; a common issue but unlikely with templates), including the library being linked against.

The form of your extern global variable appears to be correct, and that does work with templates generally speaking. The error seems specific to your templated class, but there is not information on whether that function actually exists in your posted code.

Upvotes: 1

Related Questions