Apress/beginning-cpp20

Exercise 13-1

GoolaDev opened this issue · 0 comments

Quote from the book "Exercise 13-1. define an operator function in the Box class from Ex13_05 that allows
a Box object to be post-multiplied by a numeric value to produce a new object that
has a height that is n times the original object. this should work for both integer and
fractional multiples. demonstrate that your operator function works as it should."

It says "has a height that is n times the original object" , but the code scales all dimensions.
Link to code: https://github.com/Apress/beginning-cpp20/blob/main/Exercises/Modules/Chapter%2013/Soln13_01/Box.cpp

Solution:
Box Box::operator*(double factor) const
{
  return Box{ m_height * factor };
}