C++: Simplified version of ‘Friends with benefits’ demonstrating friend classes

A friend class in C++ can access the private and protected members of the class in which it is declared as a friend.

Friendship may allow a class to be better encapsulated by granting per-class access to parts of its API that would otherwise have to be public.[2] This increased encapsulation comes at the cost of tighter coupling due to interdependency between the classes.


  • Friendships are not symmetric – if class A is a friend of class B, class B is not automatically a friend of class A.
  • Friendships are not transitive – if class A is a friend of class B, and class B is a friend of class C, class A is not automatically a friend of class C.
  • Friendships are not inherited – if class Base is a friend of class X, subclass Derived is not automatically a friend of class X; and if class X is a friend of class Base, class X is not automatically a friend of subclass Derived.

From Wikipedia:

In the following example we assign both the Man to be a friend of the Woman and the Woman to be a friend of the Man in order to allow both parties to access the private members of the other.

#include <iostream>
using namespace std;

class Man;

class Woman {
  friend class Man;

  void touch(Man man);
  void * body;

class Man {
  friend class Woman;

  void touch(Woman woman);
  void * body;

void Woman::touch(Man man) {
  void * other = man.body;

void Man::touch(Woman woman) {
  void * other = woman.body;

int main() {
  Man man;
  Woman woman;

  return 0;

Ionic comments about Atoms

Atom trust issues

Why can’t you trust Atoms?

Because Atoms make up everything!

So, You need to keep an ion them.

Atom dating issues

Why dating an atom is a bad idea?

Atoms will take electrons away from your carbon!

Also, If you split them, they blow everything up!

Atom personality

Why Atoms make good business?

Because Atoms take matter into their own hands.

And, they make everything matter!

Teenage Atoms

Why raising a teenager Atom is hard?

Because they go through phases.


Reading material