This code compiles - I don't think it should. If b is a private member of A then why can I change it outside the class ? struct A { private: int b; }; int main() { A a; a.b = 10; return 0; }