Thread: Recursive Data Structure

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    external validation
    Join Date
    Dec 2004
    Posts
    9

    Recursive Data Structure

    Hi.
    Pardon me if this is an obvious one...
    Is there a way to get around C++'s refusal to have a class member that's an instance of the class itself...?
    What I'd like is:
    Code:
    class MyClass {
      int myClassMember01;
      struct myStruct {
        int myStructMember01;
        MyClass myStructMember02;
      } myClassMember02;
    }; // End declaration of MyClass
    But what is allowed is:
    Code:
    class MyClass {
      int myClassMember01;
      struct myStruct {
        int myStructMember01;
        MyClass & myStructMember02;
      } myClassMember02;
    }; // End declaration of MyClass
    I am writing a model of a hardware architecture and it'd be conceptually much more realistic if I could use the first of the two above.
    Any suggestions?
    Is it in fact true to say that the first example is just conceptually impossible in C++?
    Cheers.
    Last edited by dwylie; 08-02-2005 at 07:00 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pthread question how would I init this data structure?
    By mr_coffee in forum C Programming
    Replies: 2
    Last Post: 02-23-2009, 12:42 PM
  2. Data structure implementation
    By fkheng in forum C Programming
    Replies: 3
    Last Post: 07-31-2003, 07:44 AM
  3. Appropriate data structure
    By gazsux in forum Game Programming
    Replies: 3
    Last Post: 03-19-2003, 01:26 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. Dynamic Data Structure -- Which one is better?
    By Yin in forum C++ Programming
    Replies: 0
    Last Post: 04-10-2002, 11:38 PM