Modify mutable member variable from a const member function
| 17 | |
| 18 | // Modify mutable member variable from a const member function |
| 19 | void Box::printVolume() const |
| 20 | { |
| 21 | // Count how many times printVolume() is called using a mutable member in a const function |
| 22 | std::cout << "The volume of this box is " << volume() << std::endl; |
| 23 | std::cout << "printVolume() has been called " << ++m_count << " time(s)" << std::endl; |
| 24 | } |