Home   |   About   |   Terms   |   Contact    
Read & Learn
 

What is a Member Function in C++?

C++

☯ All C++ Articles     ☯ All Articles


A new product.




Popular Google Pages:



◕ This article is regarding What is a Member Function in C++?
Last updated on: .



◕ Let an example first.

#include <iostream>
using namespace std;
char state = 'T';
int main()
{
cout << "Displaying char constant using Member Function, cout.put(): " << endl;
cout.put(state);
return 0;
}



The output of this program is:
Displaying char constant using Member Function, cout.put():
T



- Here cout.put() is a Member Function.

- A Member Function belongs to a class and it describes a method to manipulating the class data.
Here ostream class has a put() Member Function that is designed to output character constant such as 'T'.
Here put() is the class Member Function and cout is the class object.

- We can use a Member Function only with a particular object of that class. Here the cout is that object.



- To use a class Member Function with an object, we need a period (. full stop) to combine the object name with the function name.
This period is called the Membership Operator.



Example:
In this cout.put() Member Function we used a period sign as the membership operator.



- The cout.put() Member Function is an alternative of the << operator to display a character constant.



So why we need cout.put()?
- Because cout.put() was used in the old version of the C++ for displaying char constant such as 'A', 'B' etc.



Related articles:
Bits & Bytes
Integer Type in C++
Rules for Variable Names
Variable in C++
Fundamental Data Types & Compound Data Types




Popular Google Pages:



Top of the page

Amazon & Flipkart Special Products

   


Top of the page