struct in struct

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// test1.h
struct a
{
  int data;
  struct b
  {
    int data;
  };
};

// test2.h
struct a;
void print( const a & );

struct a::b; // why compiler can' do this?
void print( const a::b & );
Without the definition of struct a, the compiler doesn't know that there is a struct b in struct a. However, you can define struct a and leave struct b undefined until later - look up PImpl idiom for an example.
Topic archived. No new replies allowed.