也许我太愚蠢了,但这对我不起作用:
Foo.h
#ifndef FOO_H
#define FOO_H
class Foo {
public:
template<typename T>
void foo(T const &);
};
#endif // FOO_H
Foo.cpp
#include "Foo.h"
template<typename T>
void Foo::foo(T const &var) {
// do something useless
}
主文件
#include "Foo.h"
int main() {
int i;
Foo bar;
bar.foo(i);
}
我只是用 Xcode 4.4.1 编译,但它返回了以下链接错误:
Undefined symbols for architecture x86_64:
"void Foo::foo<int>(int const&)", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
感谢您的回复!