Why can I use an undefined member variable as part of a member function?

For example:

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

Why does this compile when a is not yet declared?

+7
c ++ struct class
source share
1 answer

The compiler basically performs two passes on the definition of a class or structure. One for the structure / class to parse and process member declarations, then one pass for built-in functions.

+9
source share

All Articles