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

Discussion in 'C++' started by Joseph Lanctot, Jun 21, 2004.

  1. 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
     
    Joseph Lanctot, Jun 21, 2004
    #1
    1. Advertising

  2. Joseph Lanctot

    John Carson Guest

    "Joseph Lanctot" <> wrote in message
    news:
    > 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.


    --
    John Carson
    1. To reply to email address, remove donald
    2. Don't reply to email address (post here instead)
     
    John Carson, Jun 21, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Koen
    Replies:
    1
    Views:
    506
  2. JackC
    Replies:
    3
    Views:
    599
    Alan Griffiths
    Aug 13, 2004
  3. Replies:
    5
    Views:
    511
    Markus Schoder
    Apr 16, 2006
  4. Replies:
    10
    Views:
    629
    Thomas J. Gritzan
    Sep 3, 2007
  5. Poppy
    Replies:
    1
    Views:
    404
    Poppy
    May 30, 2008
Loading...

Share This Page