Within a class declaration, include the following:
friend
For example:
friend class MyClass; // friend class
friend void MyClass::SomeFunction(); // friend class method.
friend void MyFunction(); // friend function.
When declaring friend functions and friend class methods, you must declare an unambiguous prototype, including its return type and its parameter types, and all instances of the const keyword. If the function prototype is contained in another file, that file must also be included in the class declaration file.
Friends can be declared anywhere in a class declaration. However, friends cannot be inherited so it doesn't matter if they're declared public, private or protected (access specifiers have no meaning to friends). But be aware that friends have privileged access to all members, including private and protected members. This is said to undermine the fundamentals of encapsulation, however the purpose of a friend is to extend the class interface, and is no more an undermining of encapsulation than is public inheritance. However, access should be limited to as few friends as possible; a class with many friends implies a fundamental design flaw in the class.
A constructor is a method that fires when the object is instantiated. A friend function is a function that has special access to the object. They are two different types of things, and cannot be further differenced.
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.
Only that they cannot be inherited by derived classes. This is "a good thing". Other than that, a friend function has full access to a class' private and protected members and you cannot limit its scope. At this data hiding feature of c++ is broken.
There is no such thing. When declaring a friend function only the explicitly-scoped friend is granted private access. The friend function may well be declared virtual within its own class but none of its overrides are granted access unless they are explicitly granted access.
...a function call.
Something like this:
A constructor is a method that fires when the object is instantiated. A friend function is a function that has special access to the object. They are two different types of things, and cannot be further differenced.
The keyword "friend" allows a function or variable to have access to a protected member inside a class.
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.
There is no such term as "building function" in C++.
Yes, there can be friend functions in C++.
Only that they cannot be inherited by derived classes. This is "a good thing". Other than that, a friend function has full access to a class' private and protected members and you cannot limit its scope. At this data hiding feature of c++ is broken.
There is no such thing. When declaring a friend function only the explicitly-scoped friend is granted private access. The friend function may well be declared virtual within its own class but none of its overrides are granted access unless they are explicitly granted access.
...a function call.
yes,we can make function inline
Every C plus plus program that is a main program must have the function 'main'.
Control is returning to the caller of the function.