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.
Volume of Dice1 : 210 Volume of Dice2 : 1560
JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week