No. To understand how friend functions relate to static functions you first need to understand the three qualities of a normal member function (an instance member function):
1. The function has access to the private aspects of the class in which it is declared.
2. The function is scoped to that class.
3. The function must be invoked on or from within an object of that class.
A static function only has the first two qualities (so no instance of the class is required) while a friend function only has the first quality (so is neither scoped to the class nor requires an instance of the class). All three share the first quality only but that alone does not make them similar. It is the qualities they lack that sets them apart.
A normal function is any function that is not a member of any class. Normal functions that operate upon a class are referred to as non-member functions, however a non-member function can also be a member of another class. Any class may declare any non-member function to be a friend of the class, in which case the function becomes a friend function.A member function is a member of a class and may be declared static or non-static. Non-static member functions have the following 3 properties:Private access to the class members.Scoped to the class.Must be invoked against an object of the class (has a 'this' pointer).Static member functions have the first two properties only while friend functions have the first property only. Non-member functions that are not friends of the class have none of these properties.
A static function is a member function that is not associated with any instance of the class; it has no this pointer.
Yes. Any function can be overloaded. However you cannot override a static member function. Only instance members can be overridden.
Always.
Static member functions, member function templates and constructors cannot be virtual.
A friend function is a function that cannot be declared a member of a class but which requires private access to that class. For example, a function that operates upon two different classes cannot be a member of both classes, but if the function requires private access to both classes then it has to be a friend to at least one of them.To fully appreciate friend functions, consider that a non-static member function has the following three properties:Has private access to the class.Is scoped to the class.Must be invoked against an object of the class (has a 'this' pointer).Static member functions have the first two properties only while friend functions have the first property only. All other non-member functions have none of these properties.
Private construction prevents objects from the class from being instantiated other than via a static member function of the class, a friend function or a friend class.
With respect to a given class, all functions can be split into four categories: 1. Member functions. 2. Static member functions. 3. Friend functions. 4. Non-member functions. All class member functions have the following three properties with respect to the class in which they are declared a member: 1. Private access to the class representation. 2. Scoped to the class. 3. Invoked through an instance of the class (has a 'this' pointer). Static member functions have the first two properties only. Friend functions have the first property only. Non-member functions have none of these properties.
"this" can only be used within the body of a non-static member function of a class and refers to the current instance of that class. Typically, we only refer to "this" instance when a non-static member function returns a reference to the current instance.
Static functions are tied to a class, not to a particular object. A static function can only access static variables because it has no knowledge of member variables.
The best way to understand the advantage of friend functions is to consider that a member function has the following properties:1. Private access to the class representation.2. Scoped to the class.3. Can be invoked upon an instance of the class (has a this pointer).A static member function only has the first two properties while a friend function only has the first property. All other function have none of these properties. This gives the programmer fine-grained control over which functions can access which parts of the class representation.
A normal member function has the following qualities: 1. Has private access to the class. 2. Is scoped to the class. 3. Can be invoked on an instance of the class. Static functions have the first two qualities only. Friend functions have the first quality only. It therefore follows that friend functions are only compulsory when you need quality 1 only.