Professional Documents
Culture Documents
Example
This-> Pointer
In above program, constructor have the word this. If we see the initialization of data members, the
class data members have same name as the functions parameters. The compiler can’t differentiate
so this pointer is used to point to class data member.
Example
ClassName :: ClassName(Parameters)
Friend Function
One of the important concepts of OOP is data hiding, i.e., a non-member cannot access an object's
private or protected data.
But, sometimes this restriction may force programmer to write long and complex codes. So, there is
mechanism built in C++ programming to access private or protected data from non-member
functions.
This is done using a friend function or/and a friend class. Friend function is a special type of function,
which is declared inside the class. Friend function can access the private, protected and public data
of the class. A keyword friend is used before return type of the function declaration/prototype.
Example
Example
When a class is made a friend class, all the member functions of that class becomes friend functions.
class B;
class A
friend class B;
class B
... .. ...
All member functions of class B will be friend functions of class A. Thus, any member function of
class B can access the private and protected data of class A. But, member functions of class A cannot
access the data of class B.
Ref: https://www.tutorialspoint.com/static-data-members-in-cplusplus
We can access a static member function with class name, by using following syntax:
class_name:: function_name(perameter);
Example
Ref:: https://www.includehelp.com/cpp-tutorial/static-member-function.aspx