// CSE 303, Spring 2009, Marty Stepp // This client program uses Point objects, v2. // // To compile these files: // g++ -g -Wall -c Point.cpp // g++ -g -Wall -o use_point use_point.cpp Point.o #include #include "Point.h" using namespace std; int main() { // construct two Point objects Point p1(1, 2); Point p2(4, 6); // call some methods on them cout << "p1 is: " << p1 << endl; // calls overridden <<, like toString cout << "p2 is: " << p2 << endl; cout << "dist : " << p1.distance(p2) << endl; Point p3 = p1 + p2; cout << "p1 is: " << p1 << endl; cout << "p2 is: " << p2 << endl; cout << "p3 is: " << p3 << endl; // call the overridden == and != operators Point p4 = p3; if (p3 == p4) { cout << "p3 and p4 are the same!" << endl; } if (p1 != p2) { cout << "They are not the same!" << endl; } return 0; } // alternate version that uses pointers int main2() { // construct two Point objects (using pointers) Point* p1 = new Point(1, 2); Point* p2 = new Point(4, 6); // call some methods on them cout << "p1 is: " << *p1 << endl; // p1 is: (1, 2) cout << "p2 is: " << *p2 << endl; // p2 is: (4, 6) cout << "dist : " << p1->distance(*p2) << endl; // must always free (delete) heap-allocated objects delete p1; delete p2; return 0; }