Cpp Class Member Functions
# C++ Class Member Functions
[ C++ Classes & Objects](#)
Class member functions are functions that have their definition and prototype written inside the class definition, just like other variables in the class definition. A class member function is a member of the class; it can operate on any object of that class and can access all the members of that object.
Let's look at the Box class we defined previously. Now we will use member functions to access the class members, instead of directly accessing them:
class Box{public: double length; // length double breadth; // width double height; // height double getVolume(void);// return volume};
A member function can be defined inside the class definition, or separately using the **scope resolution operator ::**. Defining a member function inside the class definition declares the function as **inline**, even if the `inline` specifier is not used. So you can define the **getVolume()** function as follows:
class Box{public: double length; // length double breadth; // width double height; // height double getVolume(void){return length * breadth * height; }};
You can also define the function outside the class using the **scope resolution operator ::**, as shown below:
double Box::getVolume(void){return length * breadth * height; }
Here, it is important to note that the class name must be used before the `::` operator. Calling a member function is done using the dot operator (**.**) on an object, which allows it to operate on the data associated with that object, as shown below:
Box myBox; // create an object myBox.getVolume(); // call this object's member function
Let us use the concepts mentioned above to set and get the values of different members of the class:
## Example
#includeusing namespace std; class Box{public: double length; // length double breadth; // width double height; // height// member function declaration
YouTip