What is the default access level for members of a class declared with the class keyword in C++?
Correct answer
A. private, unlike struct members which default to public
14 views
A. private, unlike struct members which default to public
14 views
In C++ the only difference between class and struct is the default access and default inheritance: class members are private and class inheritance is private, while struct members and inheritance are public. Many codebases therefore use struct for plain data aggregates and class for types with invariants. Forgetting the difference is a frequent cause of "member is inaccessible" errors.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is A? Ask here and get an explanation.