7

For example:

struct X{
X():a{10} {}
void foo() { a = 10; }

private:
int a;
};

Why does this compile when variable a hasn't been declared yet?

ozma
  • 349
  • 1
  • 3
  • 10

1 Answers1

9

The compiler basically does two passes over the class or structure definition. One for the structure/class to parse and handle declarations of members, then one pass for the inline functions.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621