Member functions (C++ only)
Member functions are operators and functions that
are declared as members of a class. Member functions do not include
operators and functions declared with the friend
specifier.
These are called friends of a class. You can declare a member
function as static
; this is called a static member
function. A member function that is not declared as static
is
called a nonstatic member function.
The definition of a member function is within the scope
of its enclosing class. The body of a member function is analyzed
after the class declaration so that members of that class can be used
in the member function body, even if the member function definition
appears before the declaration of that member in the class member
list. When the function
add()
is called in the following
example, the data variables a
, b
,
and c
can be used in the body of add()
. class x
{
public:
int add() // inline member function add
{return a+b+c;};
private:
int a,b,c;
};
You can use trailing return types for member functions, including those that have complicated return types. For more information, see Trailing return type (C++11).