Possible Duplicate:
Why do I get “unresolved external symbol” errors when using templates?
Why can templates only be implemented in the header file?
Maybe I'm just too stupid for it, but this doesn't work for me:
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
}
main.cpp
#include "Foo.h"
int main() {
int i;
Foo bar;
bar.foo(i);
}
I simply compiled with Xcode 4.4.1 but it returns me the following linking error:
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)
Thanks for any reply!