The signature of the first two methods are
When you implement the second method, you should use the first one.RGB& operator+=(RGB const& rhs); // Changes this object, so it is non-const method, and return reference to this object which is the result. RGB operator+(RGB const& rhs) const; // No changes to this object, so it is a const method, and return an (temparary) object which is the result.
This overloaded function cannot be a member function of the RGB class; it has to be a global function. Usually we declare it as a friend of the RGB class.ostream& operator<<(ostream& os, RGB const& rgb);
For example, assuming the canvas is of 16 by 16 size, expression "canvasObj[0][-1]" accesses an invalid address, and expression "canvasObj[0][16]" is logically wrong though it accesses a valid address(why?); however, in either case, our member function fails to report any error.
Try to write another function to access the pixel of the canvas, and do error checking for both row and colum numbers. (Hint, you have to give up [] operator overloading.)
The signatures are,round(1.2) = 1, round(1.7) = 2; round(1.5) = 2; round(-1.3) = -1; round(-1.5) = -2; interpolate(0.3, 10, 20) = (1-0.3) * 10 + 0.3 * 20 = 13. interpolate(0.5, 10, 20) = (1-0.5) * 10 + 0.5 * 20 = 15. interpolate(0.7, 10, 20) = (1-0.7) * 10 + 0.7 * 20 = 17.
int round(double); double interpolate(double t, double x1, double x2);
Now try to do interpolation between two RGB colors.double interpolate(double t, double x1, double x2);
1.3.6