Sarthaks Test
0 votes
in Computer by (26.3k points)

Explain member function:

1. inside class definition

2. outside class definition

1 Answer

0 votes
by (25.5k points)
selected by
Best answer

Class member definition describes how certain class member functions are coded.
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 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.

Related questions

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.