Class member definition describes how certain class member functions are coded.
In C++, the member functions can be coded in two ways :
- Inside class definition
- Outside class definition using scope resolution operator (::)
The code of the function is same in both the cases, but the function header is different as explained below:
1. Inside Class Definition:
When a member function is defined inside a class, we do not require to place a membership label along with the function name. We use only small functions inside the class definition and such functions are known as inline functions.
2. Outside Class Definition Using Scope Resolution Operator (::):
The member function is declared inside the function and defined outside the class using the scope resolution operator.
The syntax for a member function definition outside the class definition is :
retum_type name_of_the_class::function_name (argument list)
body of function
Here the operator :: known as scope resolution operator helps in defining the member function outside the class.