Copy Constructors

One of the important ideas underlining C++ philosophy about objects is that classes are types. Defining classes for your program extends the system of built-in C++ types. C++ wants to treat built-in types as objects. C++ also wants to treat programmer-defined types as built-in types.

For example, you can define variables of built-in types without specifying their initial values. Hence, you are able to do that for object variables.

int x; Cylinder c1;               // noninitialized variables

The syntax is the same, but the meaning is different. The definition of a variable of a built-in type just allocates memory for this variable. The definition of a variable of a programmer-defined class allocates memory for this variable and then calls ...

Get Core C++ A Software Engineering Approach 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.