22.3. Defining a new class

Just to show that making a class doesn’t need to be hard, let’s do the absolute simplest implementation of, say, a cDisk that represents a circle. Suppose we assume that we specify the circle by a cVector center, a Real radius, and a COLORREF fillcolor.

For a class which has simple fields as members, C++ defines an appropriate default no-argument constructor, a default copy constructor, a default overloaded operator=, and a default destructor. The default constructor allocates space for the data fields but doesn’t initialize them, the default copy constructor and operator= copy the data from one object to another field by field, and the default destructor simply frees up the space used by a class object. (As an aid ...

Get Software Engineering and Computer Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.