class X containing an stl list<X> in MS Visual C++

J

Joseph Lanctot

I'm trying to create a class of nodes, where each node would contain a
list of other nodes. Ideally I would like it to work like this:

class node {
list<node> children;
};

However MS Development Environment 2002 V7.0 / MS .NET Framework V1.0
will not handle this class (g++ does). The following works but I must
explicitly dereference the pointers twice (and once implicity for the
reference???) in order to access anything with a list<node
*>::iterator.

class node {
list<node*> children;
};

Is there a simple way of getting this to work with less dereferences
to access a list item via an iterator and of course no copying of the
node class.

- JKL
 
J

John Carson

Joseph Lanctot said:
I'm trying to create a class of nodes, where each node would contain a
list of other nodes. Ideally I would like it to work like this:

class node {
list<node> children;
};

However MS Development Environment 2002 V7.0 / MS .NET Framework V1.0
will not handle this class (g++ does). The following works but I must
explicitly dereference the pointers twice (and once implicity for the
reference???) in order to access anything with a list<node
*>::iterator.

class node {
list<node*> children;
};

Is there a simple way of getting this to work with less dereferences
to access a list item via an iterator and of course no copying of the
node class.

- JKL


Simplest way is to upgrade to VC++ 7.1.

node is an incomplete type when list<node> children is declared. The
standard does not require that this compile, but recent versions of some
compilers will compile it. Apparently VC++7.0 won't.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top