Question on templates?

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?


  • 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.

Howdy, Stranger!

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


In this Discussion