Main Page | File List

Lecture11AM: C++ Warming Up and RGB class.

Download.

Click here to download soource code of this lecture.

C++ operator overloading.

Overload +, += operators on RGB class. The + operator adds two RGB objects componentwise.

The signature of the first two methods are

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.
When you implement the second method, you should use the first one.

C++ exception handling.

Change the two index operators of RGB class to deal with color component overflow(>1.0). When you detect an overflow, throw an error message. In your main function, use try & catch blocks to try access the color component, and catch any error occured.

Having done above, you can go one step further-- This time dealing with index overflow, i.e., the given row or col value is not in the appropriate range.


Generated on Mon Jul 5 16:47:12 2004 by doxygen 1.3.6