nested structs

This is a discussion on nested structs within the C Programming forums, part of the General Programming Boards category; do you guys know how to do operations with nested structs like Code: struct x{ ......... struct y{........} } say ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    1

    nested structs

    do you guys know how to do operations with nested structs like

    Code:
    struct x{
    .........
    struct y{........}
    
    }
    say x is a linked list and y is also another type of linked list taht i want to exist inside x. However, the two linked lists are different in structures. The first linkedlist will store string and has a pointer to the next linkedlist and the second inner linked list will be inside the outer linkedlist keeping numbers of occurences of strings.

    Do you guys see any dangers in doing this?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    struct a;
    struct b;
    
    struct a
    {
        struct *b;
        ... stuff ...
    };
    
    struct b
    {
        struct *a;
        ... stuff ...
    };
    You cannot make A contain B and B contain A, but you can make them contain pointers to the other type. Nesting structures is fine unless you try to make them contain eachother.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. nested structs
    By bandal27 in forum C Programming
    Replies: 26
    Last Post: 12-13-2008, 08:14 PM
  2. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 04:01 PM
  3. Nested structs
    By Sir Andus in forum C Programming
    Replies: 5
    Last Post: 11-28-2006, 09:31 AM
  4. Nested Structs
    By Monkey83 in forum C Programming
    Replies: 2
    Last Post: 09-15-2006, 11:03 AM
  5. accessing members in nested structs
    By amidstTheAshes in forum C Programming
    Replies: 2
    Last Post: 03-23-2005, 01:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21