Results 1 to 4 of 4

Thread: Forward Declaration

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Location
    Orlando, FL
    Posts
    253

    Forward Declaration

    I have 2 structures that contain each other..
    Code:
    typedef struct tagUSER {
        long lName
        GROUP group
        const char *lpszPass
    }; USER
    
    typdef struct tagGROUP {
        long lID
        USER user
    }; GROUP
    It doesnt work. Is there a way to forward the declaration for the
    structures so they can see each other?
    Always looking for a better and faster way!

  2. #2
    Zaei
    Guest
    Placing the line:
    Code:
    struct tagGROUP;
    before the first struct should solve the problem.

    Z.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    It does not and it's good that way. Two structs that contain each other (or one that contains itself) would actually need infinite memory.

    If you need something like this, keep a pointer to a struct of the other type, but don't create access violations

    Then you still need a forward declaration like Zaei showed.


    And the alternative names for your structs must come before the semicolon:
    } GROUP;
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    Zaei
    Guest
    Oh, I didnt catch that =(.

    Z.

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