Question on templates? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Question on templates?

evader23evader23 Posts: 4Member
Ok I have the following code

template class TLinkList
TItem FHead;
TItem *FItem;
unsigned short FCount;
unsigned short FPos;
void Intialize(void);
void Add(T Data)
if(FCount == 0)
FItem->Cur = Data;
FItem->Next = new TItem;
FHead.Next = FItem;
FItem = FHead.Next;
while(FItem->Next != NULL)
FItem->Cur = Data;
FItem->Next = new TItem;
FCount += 1;

void Next()
FItem = FItem->Next;
FPos += 1;

inline unsigned short Count(){return FCount;}

template void TLinkList::Intialize()
FHead.Next = new TItem;
FItem = new TItem;
FCount = 0;
FPos = 0;

When all in the same file it compiles fine, But I want to be able to move the body of the functions to the .cpp file so the .h file isn't so cluttered(not mention is bad form. problem is when I do that I get a liker error. How do I get it to compile with the class defintions in the header file and the Body of the fuctions in the .cpp file?


  • smnssmns Posts: 11Member
    is it possible at all with templates? i dont think so. after all, the compiler has to see the body to generate code, same as inline functions. all u can do is to move the code out the class definition, i.e. u can write:
    template A::f() {...} etc or
Sign In or Register to comment.