How about this to bake your noodle:-
template< class T >
class CTFLink
{
public:
CTFLink()
{
m_pNext = 0;
}
CTFLink( T _t ) : m_Item( _t )
{
m_pNext = 0;
}
void Append( CTFLink< T >* ptNext )
{
CTFLink< T >* pEnd = this;
while( pEnd->m_pNext != 0 )
{
pEnd = pEnd->m_pNext;
}
pEnd->m_pNext = ptNext;
}
T& Item()
{
return m_Item;
}
T m_Item;
protected:
CTFLink< T >* m_pNext;
};
It can be used by deriving a class from it, which instantly becomes a linked list of itself.
class CMyThing : public CTFLink< CMyThing >
{
...
Not perhaps the recommended way of doing things but it's fun and possibly the worlds simplest generic linked list. Can you come up with a simpler one?