+2 votes
in Class 12 by kratos

What is meant by referencing member functions inside class definition and outside class definition?

1 Answer

+5 votes
by kratos
 
Best answer

In C++, the member functions can be coded in two ways :

  1. Inside class definition
  2. 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 membership label along with the function name. We use only small functions inside the class definition and such functions are known as inline functions.
In case of inline function, program ***** is faster but memory penalty is there.

2. Outside Class Definition Using Scope Resolution Operator (::)

The member function declared in the class must be defined outside the class. Here the operator :: known as scope resolution operator helps in defining the member function outside the class.
In this case the function’* full name (qualified_name) is written as shown: Name_of_the_class :: function_name()
The syntax for a member function definition outside the class definition is:

return type name_of_the_class::function_name (argument list)
{
body of function;
}

...