friend classes in c++

A friend class in C++, can access the private.protected and public members of the class in which it is declared as a friend. On declaration of friend class all member function of the friend class become friends of the class in which the friend class was declared. Friend status is not inherited; every friendship has to be explicitly declared.

Example

#include <iostream>

class B
{
	// B declares A as a friend...
	friend class A;

private:
	void privatePrint()
	{
		std::cout << "firend classes" << std::endl;
	}
};

class A
{
public:
	A()
	{
		B b;
		// ... and A now has access to B's private members
		b.privatePrint();
	}
};

int main()
{
	A a;
	getchar();
	return 0;
}