Lorem ipsum dolor sit amet, consectetur adipiscing elit. Test link
Posts

8.3 Friend Function

1 min read
Image result for Friend Function c++
A friend function of a class is defined outside that class' scope but it has the right to access all private and protected members of the class. Even though the prototypes for friend functions appear in the class definition, friends are not member functions.

A friend can be a function, function template, or member function, or a class or class template, in which case the entire class and all of its members are friends.

To declare a function as a friend of a class, precede the function prototype in the class definition with keyword friend as follows:
class ABC
{
double a;
public:
double b;
friend void printWidth( ABC abc );
void setWidth( double c );
};

To declare all member functions of class XYZ as friends of class ABC, place a following declaration in the definition of class ABC:
friend class XYZ;

                      8.4 Inheritance          NEXT >>

You may like these posts

  •   An operator is a symbol. Compiler identifies Operator and performs specific mathematical or logical operation. C provides following operators : # Arithmetic Operators # L…
  • In Array we can store data of one type only, but structure is a variable that gives facility of storing data of different data type in one variable. Structures are variab…
  • refers to where variables is declared. It can be Inside a function or a block which is called local variables, In the definition of function parameters which is called f…
  • auto The default class. Automatic variables are local to their block. Their storage space is reclaimed on exit from the block. register If possible, the variable will be…
  • Array is a fixed size collection of similar data type items. Arrays are used to store and access group of data of same data type. Arrays can of any data type. Arrays must…
  • Pointer is a variable that stores the address of another variable. They can make some things much easier, help improve your program's efficiency, and even allow you to handle u…

Post a Comment