CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2007
    Location
    Lithuania
    Posts
    98

    [RESOLVED] Dynamic ? Nested structs

    Good day to everyone. I am a bit lost , and I hope someone could help me a bit

    Lets say I have a struct which could have the same look of struct as itself and that child struct the same ant so on ..

    How to declare it....

    Pseudo code
    Code:
    struct1
    {
       variables;
       next_struct_like_struct 1
       {
            variables;
               next_struct_like_struct_before.....
       }
    }
    Thankyou in advice.
    Share and always try to give back more.

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Dynamic ? Nested structs

    You could use a member pointer, e.g.,
    Code:
    struct X
    {
        int z;
        X* next;
    };
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Dec 2007
    Location
    Lithuania
    Posts
    98

    Re: Dynamic ? Nested structs

    So you saying. that X* next will make lika a copy of new struct.
    Hmm somehow I was trying to make it work like a class with (new = ) and constructor :x
    Share and always try to give back more.

  4. #4
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Dynamic ? Nested structs

    Quote Originally Posted by ulumulu
    that X* next will make lika a copy of new struct.
    No, but it can point to another struct of the same type, or even point to the same struct.

    Quote Originally Posted by ulumulu
    Hmm somehow I was trying to make it work like a class with (new = ) and constructor :x
    Go ahead. You would need to consider ownership though: does an object own another object of the same type, or is it merely associated with that other object?
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  5. #5
    Join Date
    Dec 2007
    Location
    Lithuania
    Posts
    98

    Re: Dynamic ? Nested structs

    Well relation between objects are actually weak. Anyway thankyou laserLight.
    Share and always try to give back more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured