2014-03-26 2 views
0

링커에 문제가 있습니다. 그것은 나에게 다음과 같은 오류를 제공템플릿 메서드의 링커 오류

다음과 같이

[Linker error] undefined reference to `bool Polis :: deleteEdifice <Mine> (int) ' 

이 프로토 타입이 선언 :

template <typename T> bool deleteEdifice(int); 

deleteEdifice 지금은 아무것도하지 않고 작동하지 않는, 비어 있습니다.

프로토 타입에 대한 호출은 다음과 같습니다

obj->template deleteEdifice<Mine>(3); 

인쇄 다음과 같은 오류 :

`template' (as a disambiguator) is only allowed within templates 

당신이 내가 뭘 오전 말해 수를

obj->deleteEdifice<Mine>(3); 

나는 또한하려고 노력 잘못하고있다. 이

template <typename T> bool deleteEdifice(int); 

+0

"deleteEdifice가 지금은 아무것도하지 않고 작동하지 않습니다, 비어 있습니다." '당신의 코드는 다음과 같은 가정 해요 명확히하십시오. 무슨 뜻이에요? 이 문장과 관련된 코드가 있습니까? 보여줄 수 있습니까? –

+2

선언하는 것뿐만 아니라 헤더 파일에 템플릿을 정의해야합니다. 'template bool deleteEdifice (int) {}' – clcto

+0

.cpp 파일에서'deleteEdifice'의 정의입니까? –

답변

0

는 그것이 오류처럼 정의되지 의미, 비어 의미하지 않는다 [Linker error] undefined reference

template <typename T> bool deleteEdifice(int) { return false; } 

+0

같은 오류가 발생했습니다 : [링커 오류] 'bool Polis :: deleteEdifice (int)'에 대한 정의되지 않은 참조 ' – angel

0

I'm having problems with the linker. It gives me the following error: [Linker error] undefined reference to `bool Polis :: deleteEdifice (int) '

I 비어

또한
//.h file 
class Polis 
{ 
    public: 
    //...constructor etc... 
    template <class T> 
    bool deleteEdifice(int); 
}; 

.H 파일

//, where definition of template is visible at 
// point of instantiation - remember, template is instantiated 
// when used (in compilation unit where used), therefore its 
// definition has to be visible in the scope where used. It is 
// only instantiated when used... If it's definition is not 
// available at the point of instantiation (where called for 
// a function template), it is never 
// compiled. 

template <class T> 
bool Polis::deleteEdifice(int) 
{ 
    //Implementation here... 
} 
+0

동일한 오류가 발생했습니다. [링커 오류] 'bool Polis :: deleteEdifice (int) '에 대한 정의되지 않은 참조 – angel