Skip to content

Exercise 13-1 #47

@GoolaDev

Description

@GoolaDev

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 };
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions