recategorized
3,448 views
0 votes
0 votes

If a function is friend of a class, which one of the following is wrong ?

  1. A function can only be declared a friend by a class itself.
  2. Friend functions are not members of a class, they are associated with it.
  3. Friend functions are members of a class.
  4. It can have access to all members of the class, even private ones.
recategorized

1 Answer

2 votes
2 votes

ans is C  friend function is not a member of class it works as a bridge  between 2 classes

one of the most convenient and controversial feature of C++ is allowing non -memeber function   to   access even the private members of a class using friend function or friend classes . It permits  a function or all  the  functions of another class to access a different class's private members 

In object-oriented programming, a friend function, that is a "friend" of a given class, is a function that is given the same access than methods to private and protected data[1]

A friend function is declared by the class that is granting access, so friend functions are part of the class interface, like methods. Friend functions allow alternative syntax to use objects, for instance f(x) instead of x.f(), or g(x,y) instead of x.g(y). Friend functions have the same implications on encapsulation than methods.

Related questions

0 votes
0 votes
1 answer
1
0 votes
0 votes
1 answer
2
makhdoom ghaya asked Sep 24, 2016
2,142 views
In C++, polymorphism requires :Inheritance onlyVirtual functions only References onlyInheritance, Virtual functions and references
3 votes
3 votes
2 answers
3
0 votes
0 votes
1 answer
4