Before you ask, yes the function is defined in the header of my template class.
Here's the relevant bits of Example.h
:
template<class T, class J, const int X, const int Y>
class Example {
public:
friend std::ostream& operator<<(std::ostream& s, const Example<T,J,X,Y>& b);
}
template<class T, class J, const int X, const int Y>
std::ostream& operator<<(std::ostream& s, const Example<T,J,X,Y>& b) {
// stuff
}
I'm calling it from main.cpp
:
void foo(Example<A,B,5,5>& b) {
std::cout << b;
}
int main() {
Example<A,B,5,5> b = Example<A,B,5,5>();
foo(b);
}
When compiling I get the following linker error:
Undefined symbols for architecture x86_64:
"operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, Example<A, B, 5, 5> const&)", referenced from:
foo(Example<A, B, 5, 5>&) 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)
make[2]: *** [dist/Debug/GNU-MacOSX/consolehero] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2