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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access