I have this function declaration:
template<class T>
a::A& a::A::operator<<(T out) {
std::cout << out;
return (*this);
}
and this function definition:
namespace a {
...
class A {
...
template<class T> A& operator<<(T);
And I call it as:
a::A b;
b << 1;
and this is the Makefile:
app: main.o A.o
g++ main.o A.o -o app
main.o: main.cpp
g++ -c main.cpp
A.o: A.cpp
g++ -c A.cpp
and it gives me:
Undefined symbols: a::A& a::A::operator<< <int>(int)
why is that?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…