| < Day Day Up > |
|
Research: Procure a copy of James O. Coplien's excellent book Advanced C++ Programming Styles and Idioms and read it from front to back.
Default Constructor and Destructor: Given the following code for Baseline class:
#ifndef BASELINE_H #define BASELINE_H class Baseline { public: virtual f(); private: int x; int y; char* name; }; #endif
Add a default constructor that provides default values for Baseline attributes x, y, and name. Dynamically allocate memory for the name attribute.
Add a destructor that properly releases the memory allocated during the constructor call.
Write a driver program to test your code.
Copy Constructors: Building upon the Baseline code of the previous exercise, add a copy constructor that creates new Baseline objects from existing Baseline objects.
Copy Assignment Operator: Building upon the Baseline code resulting from the previous exercise, add a copy assignment operator to properly change the attributes of an existing Baseline object to those of another existing Baseline object. Keep in mind the difference between a shallow copy and a deep copy.
Overloaded Equality Operator: Building upon the Baseline code resulting from the previous exercise, add a equality operator so that Baseline objects can be compared with each other.
Overloaded Greater-Than Operator: Building upon the Baseline code resulting from the previous exercise, add a greater than operator so that Baseline objects can be compared with each other.
| < Day Day Up > |
|