Defining operations
76
Adding a Copy constructor to a class
The body of a Copy constructor contains a copy of the attributes of the class
that exist at the moment of the creation of the constructor.
When you create a Copy constructor, it has the same as that of the class,
prefixed by the keyword new. It has a default parameter that you can modify,
or you can add other parameters.
If the class is an instance of another class, the attribute names within the body
of the Copy constructor operation are the same as those in the parent class.
You can define only one Copy constructor to any given class.
v To add a Copy constructor to a class:
1 Double-click a class in the model.
2 Click the Operations tab.
3 Click the Add button.
4 Select Copy Constructor from the dropdown list.
A Copy constructor is created at the end of the list of operations for the
class. It has the same name as the class to which it belongs.