C++ call method with template 'Error'

Hello everyone, I'm having problems with the linker.

It gives me the following error:
[Linker error] undefined reference to `bool Polis :: deleteEdifice <Mine> (int) '

The prototype is declared as follows:
template <typename T> bool deleteEdifice(int);
deleteEdifice is empty, that does not do anything for now but it does not work.

The call to the prototype is:
obj->deleteEdifice<Mine>(3);

I also tried to do:
obj->template deleteEdifice<Mine>(3);
Print the following error:
`template' (as a disambiguator) is only allowed within templates

Could you tell me what am I doing wrong.
Last edited on
@ne555: I'm sorry but I could not solve, could you give me a hand?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//.h file
class Polis
{
  public:
    //...constructor etc...
    template <typename T>
    bool deleteEdifice( int );
};

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


call method: obj->deleteEdifice<Mine>(3);
It gives me the following error: [Linker error] undefined reference to `bool Polis :: deleteEdifice <Mine> (int) '
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//.h file
class Polis
{
public:
	//...constructor etc...
	template <typename T>
	bool deleteEdifice( int );
};

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

class Mine{};

int main(){
	Polis *obj;
	obj->deleteEdifice<Mine>(3);
}
builds fine
Again, look at point 6.


By the way, ¿why is that function a template?
Last edited on
Topic archived. No new replies allowed.