Member of a class can be accessed only through the object of a class. The members are accessed as follows:
p.member;
pl.member;
p2.member;
The member may be a member function or member data. The dot operator is also called the class member access operator. This is used for associating the object name with the member function.
Following are some examples to show the use of public and private accesses.
Example
An example to show that member data can be declared in the class whereas the values can be provided outside the class.
#include #include class base { public: int s1, s2; }; void main() { clrscr(); base p; p.s1 = 5; p.s2 = 6; cout<<p.s1<<" "<<p.s2; }
In the above example, s1 and s2 have been declared to be public.