Pergunta

i got the following error

"Fehler 9 error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: bool __cdecl gameClass::getAttribute(class std::basic_string,class std::allocator >)" (??$getAttribute@_N@gameClass@@QEAA_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)" in Funktion "main". C:\Users\Weexe\documents\visual studio 2010\Projects\Engine\Engine\main.obj Engine "

My Code class.h

template <typename T> T getAttribute(std::string attribute);

class.cpp

template <typename T>
T gameClass::getAttribute(std::string attribute)
{
std::map<std::string,int> matchAttribute;

matchAttribute["windowTitle"]=1;
matchAttribute["windowSizeX"]=2;
matchAttribute["windowSizeY"]=3;
matchAttribute["isMenue"]=4;

switch(matchAttribute[attribute])
{
case 1:
    return this->windowTitle;
    break;
case 2:
    return this->windowSizeX;
    break;
case 3:
    return this->windowSizeY;
    break;
case 4:
    return this->isMenue;
    break;
}
}

Any one have an idear how to fix that error ? I think its a syntax error or smth like that :/

Foi útil?

Solução

Templates can only be implemented in header files (.h, .hpp, .inl) e.t.c. This means that the code in class .cpp wil have to be 'bonded' with the code in class.h, to make a new header file.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top