« Constant functions in C++ objects

Constant functions

Which don't change any properties of the current object. If from some member function we are not altering any properties of the current object then we should mark it as const so that we can call this function from a const object.

Whenever we are creating a class, we should mark all the functions as const which are not changing at properties of the object so that we will be able to call those from a const object

1int getNumerator() const { return numerator; }
2
3int getDenominator() const { return denominator; }
4
5void print() const
6{
7 cout << this->numerator << " / " << this->denominator << endl;
8}

For full class code to try out the code yourself:

https://github.com/anishakd4/ds/tree/master/cn/oops