I don't use C++ very often, so probably I'll post dummy question.
I have base class
class BaseObject {
public:
template <class T> T* addIntoAutoreleasePool(T*);
};
Its implementation:
template <class T>
T* BaseObject::addIntoAutoreleasePool(T* argument) {
return argument;
}
When I use this method in BaseClass with this code:
BaseObject::BaseObject() {
int a = 5;
this->addIntoAutoreleasePool<int>(&a);
}
it works fine, but if I use this code in child class:
class MazeGame : public BaseObject {
public:
Maze* createMaze();
};
Maze* MazeGame::createMaze() {
int a = 5;
this->addIntoAutoreleasePool<int>(&a);
}
compiller complains:
Undefined symbols for architecture x86_64:
"int* BaseObject::addIntoAutoreleasePool<int>(int*)", referenced from:
MazeGame::createMaze() in MazeGame.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
My IDE is XCode 8. I Have some ideas why it happens:
- If I use addIntoAutoreleasePool method in both base and child classes it works fine.
- So... I have to force methods generation for needed type.(but I don't know how. I hoped that C++ must do it automatically.). And I need this method for "any type" in me future code, custom classes, ints etc.
- Probably it is just some XCode bug. But any way I have to solve this problem somehow. =(
PS :Anyway, thanks for attention =)