#include // allows use of cin and cout #include "Point.h"; #include "ColorPoint.h"; #include "output.h"; using namespace std; int main(){ string test = "hello"; Point p(0,0); // calls the Point constructor cout << "p = " << p << endl; p.translate(1,5); cout << p << endl; Point *q = new Point(5,7); // allocated a reference to a point using // new cout << *q << endl; q->translate(3,-1); cout << *q << endl; cout << endl << "Starting color points" << endl; ColorPoint cp(1,2,"red"); // again avoid direct use of constructor cout << cp << endl; // what happens when a colorpoint is assigned to a point variable p = cp; // bad news, it is truncated to a point! cout << p << endl; p.translate(1,2); // uses point code, not colorpoint cout << p << endl; // Correct way is to use pointers and "new". ColorPoint *cq = new ColorPoint(3,4,"red"); cout << *cq << endl; q = cq; q->translate(2,2); cout << *q << endl; // Assigning colorpoint to Point pointer Point *pp = q; pp->translate(5,0); // Now get expected result!! cout << *pp << endl; return 0; }