Allowing a struct to refer to itself - C++ Data Type

C++ examples for Data Type:struct

Description

Allowing a struct to refer to itself

Demo Code

typedef struct SelfReferential {
   int i;/*from   w  w  w  .j  a  v a 2  s . co m*/
   SelfReferential* sr; // Head spinning yet?
} SelfReferential;
int main() {
   SelfReferential sr1, sr2;
   sr1.sr = &sr2;
   sr2.sr = &sr1;
   sr1.i = 47;
   sr2.i = 1024;
}

Related Tutorials