function1( alpha a, beta b); to have access both the private data members I.e. data1 of beta and alpha class. So we make it a friend function. It is declared with the friend keyword in both the classes.
This deceleration can be placed anywhere in the class. It does not matter if it goes in the public or private section.
An object of each class is passed as an argument to the function function1( alpha a, beta b); and it accesses the private data member of both classes through these arguments.
Remember that class cannot be referred to until it has been declared. Notice that class beta is referred to in the declaration of the function function1( alpha, beta ); in class alpha, so beta must be declared before alpha.