/// File shapetest.cc, by KWR for CSE250 S'00. Test code for Java2C++ handout. /// To keep this example small, I put all classes and main() in one file. #include #include class Shape {}; class ClosedCurve: public Shape { public: virtual double area() const = 0; ///doesn't say the area is always zero :-) }; class Rectangle: public ClosedCurve { double length, width; ///not pointers since primitive types. public: Rectangle(int ell, int w): length(ell), width(w) {} virtual double area() const { return length*width; } }; ///Note ^^^^^^ implicit conversion ^^^^^^ going on here! int main() { Rectangle* rp = new Rectangle(3.0,4.0); Rectangle r(5.0,7.0); string str = "abcde"; cout << str << rp->area() << r.area() << endl; } /// Note: Delete the "()" from either occurrence of "area" and see how many /// error messages you get!!! /// Then try deleting either "const", and see what message(s) you get. /// Also see what happens if you delete ";" after closing class braces.