recursive templates ?

I could easily write a recursive list (list that contains lists) without templates (struct list{ list *object, *next; };), however I can't figure out a way to use an std::list (or whatever other template) in a recursive way. I do understand that this is sort of abuse and that what I really want is a binary tree. It would be very interesting if someone knew or could figure out how to do this though. I wonder if it is possible..
I've been using a list that can hold other lists for a program I'm writing in C. I use a pointer to void to hold nodes and an int to signal whether the pointer points to another list or to a "terminal" node.
Oh wait.. struct Dummy{ std::list<Dummy> d; }; works fine ( though it doesn't look too pretty ). I guess making threads about things helps me think..
Isn't there a danger of that being truly recursive if you are not careful.
Sort of, but apparently C++ takes care of that.
1
2
3
4
5
6
7
8
template<typename T>
struct Template{
   T t;
};

struct Dummy{
   Template< Dummy > d;
};
says
error C2079: 'Template<T>::t' uses undefined struct 'Dummy'
I've once managed to make g++ compile forever because of recursive templates.

But you can have a member list of objects of the class itself, because a list can be empty so it doesn't require infinite memory to store an object ( and the list objects would be allocated in some other part of memory anyway )
Topic archived. No new replies allowed.