class a{public: void sat(){x=6;y=5;}
int x;
private:int y;};
DOUBT: in above class in member function sat "x" variable is used before its declaration. you can see that y is declared in private access specifier after it is used in member function.why is this happening?
can we use a variable before its declaration in case of classes? if so why?
what are the other provisions that classes give to us ?
The C++ compiler is a multi-pass compiler. On the first pass, the compiler (among other things) performs syntactic checking of the code. Semantic checking comes later. In your example above, the compiler sees the line "x=5; y=5;" and decides that syntactically this is valid.
Note that you would achieve the same behavior had you declared "a" as a struct instead of a class.