The difference is that if you write friend A; , A must be a known type name, that is, it must be declared earlier.
If you write friend struct A; , this is itself an A declaration, so a preliminary declaration is not required:
struct B { friend struct A; };
However, there are several subtleties. For example, friend class/struct A declares class A in the innermost namespace of class B (thanks to Captain Obvlious ):
class A; namespace N { class B { friend A;
There are also several other cases where you can only write friend A :
A is the name of typedef:
class A; typedef A A_Alias; struct B {
A is a template parameter:
template<typename A> struct B {
Anton Savin
source share