5. The header of the point class is as follows: 1. class point 3. public: 4 5 6
ID: 3711334 • Letter: 5
Question
5. The header of the point class is as follows: 1. class point 3. public: 4 5 6 // CONSTRUCTOR point (double initial_x - 0.0, double initial y-0.0); // MODIFICATION MEMBER FUNCTIONS void set_x (double& value); void set_y (double& value); 10. 11. // CONST MEMBER FUNCTIONS 12. 13 14. private: 15 16 17 18. point operator+ (double& in) const; double x; // x coordinate of this point double y; I/ y coordinate of this point Which line of the following code results in error? Explain why 1. main() point myPointl, myPoint2, myPoint3; double shift- 8.5; myPointi- shift myPoint2; myPoint3-myPoint1.operator+ (shift); myPoint1-myPointl + shift; 4 6Explanation / Answer
line 4 will produce an error Reason: because there is no matching operator for double + point Fix: To fix it there should be friend function which overrides operator + to implement double+point friend point operator+(double& in, point &p) const;
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.