Javatpoint Logo
Javatpoint Logo

C++ Class Member Functions

A class member function is a function that, like any other variable, is defined or prototyped within the class declaration. It has access to all the members of the class and can operate on any object of that class.

Let us use a member function to access the members of a previously created class instead of directly accessing them.

Member functions can be defined either within the class definition or separately with the scope resolution operator,:. Even if the inline specifier is not used, specifying a member function within the class declaration declares the function inline. So, you may either define the Volume() function as shown below.

If we want, we may define the identical function outside of the class using the scope resolution operator (::), as seen below.

The main thing to remember here is that we must use the class name exactly before the :: operator. The dot operator (.) will be used to perform a member function on an object and will only manipulate data relevant to that object as follows:

Let us apply the techniques discussed above to set and get the values of various class members of a class.

C++ Program:


Volume of Dice1 : 210
Volume of Dice2 : 1560

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA