Chapter 11

1: Use a member function to overload the multiplication operator for the Stonewt class; have the operator multiply the data members by a type double value. Note that this will require carryover for the stone-pound representation. That is, twice 10 stone 8 pounds is 21 stone 2 pounds.
A1: Here's a prototype for the class definition file and a function definition for the methods file:
// prototype
Stonewt operator*(double mult);
// definition -- let constructor do the work
Stonewt Stonewt::operator*(double mult)
{
    return Stonewt(mult * pounds);
}
2: What are the differences between a friend function and a member function?
A2: A member function is part of a class definition and is invoked by a particular object. The member function can ...

Get C++ Primer Plus, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.