Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
+1 vote
18.4k views
in Computer by (26.0k points)

Explain member function:

1. inside class definition

2. outside class definition

1 Answer

+1 vote
by (25.0k 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.
Example;

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.

Categories

...