我不经常使用C ++,所以我可能会发布虚拟问题。
我有基类
class BaseObject {
public:
template <class T> T* addIntoAutoreleasePool(T*);
};
其实施:
template <class T>
T* BaseObject::addIntoAutoreleasePool(T* argument) {
return argument;
}
当我在 BaseClass 中使用此方法时,使用以下代码:
BaseObject::BaseObject() {
int a = 5;
this->addIntoAutoreleasePool<int>(&a);
}
它工作正常,但如果我在子类中使用此代码:
class MazeGame : public BaseObject {
public:
Maze* createMaze();
};
Maze* MazeGame::createMaze() {
int a = 5;
this->addIntoAutoreleasePool<int>(&a);
}
compiller抱怨道:
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)
我的IDE是XCode 8.我有一些想法为什么会发生:
PS:无论如何,感谢关注=)