Hey everyone, I'm trying to write a templated class and place member function code outside of the class definition. I'm using Dev C++ with the gcc compiler. When I try to compile my code, i get a linker error
[Linker error] undefined reference to 'foo<int>::sum()'
Id returned 1 exit status
I can seperate member function source files from the class definition source file if i'm not using a templated class, but I can't do it when I try to use a templated class. Here's the contents of my source files
template <typename T>
T foo<T>::sum() {
return x + y + z;
}
Now if I take the contents of "sum.cpp" and stick it to the end of "foo.h" it compiles fine. It's just when i seperate the source files that I get a linker error. I don't want to do this, however, because it increases compile time by quite a bit especially when I have a big program. (i think it's b/c the my IDE compiles .cpp files only once but has to re-comile .h files everywhere they're included but not entirely sure)