Are there any known precautions I should take when building code with a generic class? I've made sure to fully define my classes in the source file, i.e:
template<typename T> void C1<T>::foo(){...}
The reason I ask is that I'm getting undefined reference errors at link time, such as:
error: undefined reference to C1<int>::foo()
My header file is included, and the namespaces match up. Any other things I should be watching out for?
Actually, that is the definition, I just truncated out the code. The declaration is in the header, where it's declared as:
1 2 3 4 5
template<typename T> class C1
{
...
void foo();
};
Would it help if I posted the header and source on the net? Be advised that it's about 150 lines in total, and there's a couple of other classes in there too...
...through magic telepathic abilities, of course...
My apologies. The class is question is ObjectManager, and unfortunately all of its methods are problematic. Each one gives me an undefined reference error.
Actually, now that I look closer, ObjectManager is the only class there. :-P
Are you sure you're compiling the cpp along with the rest of the project? I don't see any discrepancies between the declaration and definition signatures.
You can use this example to see how template methods should be declared and defined:
ahh, for real? Yeah, they're defined in a header/source pair. Jeez, that is weird. I'll give it a shot and put them in the header. Thanks a lot for the tip!