Thread: 2 structures to reference each other

  1. #1
    zsaniK Kinasz's Avatar
    Join Date
    Jan 2003
    Posts
    222

    2 structures to reference each other

    Is there a way to get to get this to work...

    // header1.h
    struct s1{
    struct s2 * s2_ptr;
    };

    // header2.h
    struct s2{
    struct s1 * s1_ptr;
    };

    I think i've seen the kernel do it but i cant find it again to replicate.( if i wasnt dreaming );
    "Assumptions are the mother of all **** ups!"

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    This should work (I don't have a compiler right now).
    Code:
    struct s2;
    
    struct s1{
    struct s2 * s2_ptr;
    };
    
    // header2.h
    #include <header1.h>
    struct s2{
    struct s1 * s1_ptr;
    };
    Last edited by XSquared; 04-07-2004 at 05:43 AM.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    /* st1.h */
    struct s2; /* we use an "incomplete reference" */
    struct s1
    {
        struct s2 *s2ptr;
    };
    
    /* st2.h */
    struct s1;
    struct s2
    {
        struct s1 *s1ptr;
    };
    Both have to end up in the same scope though. Becuase you must complete all "incomplete references".

    [edit]
    Curses, foiled again.
    [/edit]

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

  4. #4
    zsaniK Kinasz's Avatar
    Join Date
    Jan 2003
    Posts
    222
    thanks both
    "Assumptions are the mother of all **** ups!"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM