Professional Documents
Culture Documents
member functions of the class where they are declared. The private
class.
Protected
Protected members are accessible by the class itself and it’s sub-
classes. The members with protected specifier act exactly like private
as long as they are referenced within the class or from the instance of
the class. This specifier specially used when you need to use
inheritance facility of C++. The protected members become private of
a child class in case of private inheritance, public in case of public
inheritance, and stay protected in case of protected inheritance.
Access Specifier Visible to own class Visible to objects of
members same/other class
Private Yes No
Protected Yes No
Friend Functions
functions of the friend class also become the friend of the other
class. This requires the condition that the friend becoming class
yourclass.Secret = x;
}
};
int main()
{
MyClass my_class;
SecondClass sec_class;
my_class.printMember();
sec_class.change( my_class, 5 );
my_class.printMember();
return 0;
}
Output
0
5
In this program we are using the SecondClass object to access