Lecture overview -- Keyboard shortcut: 'u'  Previous page: Visibility and Access Control -- Keyboard shortcut: 'p'  Next page: Friends - Example 1 -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 3 - Page 28 : 36
Notes about C++
Abstraction Mechanisms, Part 1
Friends

A friend of class C has access to private and protected members of C

  • The C++ Programming Language: Page 278-282
 

  • Friendship principles:

    • Friendship is provided by the class that encapsulate members with access limitations

      • Friendship cannot be taken by a class or function that wants access

    • Friendship can be granted to

      • an ordinary function, or to an overloaded operator

      • a member function in another class

      • all members of another class

    • Friendship is not transitive, and it is not inherited

In some cases it is convenient define a function as a friend instead as a member.

Because a friend is activated in another way than a member: f(x,y) versus x.f(y).