Archived

This topic is now archived and is closed to further replies.

InfestedFurby

templated classes and multiple files

Recommended Posts

ok heres the problem... i have written a basic templated linked list class (it works, ive tested) and i want to split it up into multiple files ala main.cpp list.h and list.cpp in list.h there is template class LINKEDLIST{ public: //variables omitted for brevity void add_node(t data); } in list.cpp there is #include "list.h" template void LINKEDLIST::add(t data) { //this actually does stuff when i dont cut out all the code } and in main.cpp there is #include "list.h" int main(void) { LINKEDLIST bla; } now the thing above compiles.... but when i add the following to it bla.add(6); i get this error undefined reference to LINKEDLIST::add(int) anyone know why this is? ps it only does this with templated classes... normal ones work fine thanx to any who respond

Share this post


Link to post
Share on other sites
The whole template needs to be in the header because they are not normal classes. With non-templated classes the size of the class will always be the same but a template can accept any data type of any size so they are handled differently.

Invader X
Invader''s Realm

Share this post


Link to post
Share on other sites