I wanted to get a clearer idea of the differences between public
, private
and protected
members in c++.
-Anything that is public
is available to all derived classes of a base class, and the public
variables and data for each object of both the base and derived class is accessible by code outside the class.
-Not only are the functions and variables marked private
not accessible by code outside the specific object in which that data appears, but private
variables and functions are not inherited
-Variables and functions marked protected
are inherited by derived classes; however, these derived classes hide the data from code outside of any instance of the object
I guess I'm not really clear on the differences between private
and protected
. Are private
members accessible only to the method of the class
?
Is there access to private
members of a class by any function defined outside the class
?