Homework 12
Due : 9.30am, 26 July
Answer the following questions on Copy Constructors:
- What is a copy constructor ?
- Describe two instances in which we NEED a copy constructor (ie when
not having it could result in errors) ?
- How many parameters does a copy constructor take ?
- What are the types of the parameters ?
- What is the return type of a copy constructor ?
Solution
- A copy constructor is a function called automatically by the compiler
to create a copy of an object.
-
- When we want to pass an object as a value parameter to a function and
the object has dynamic variables.
- When we initialize a new object (at the point of definition)
using an existing one (eg. Node a; Node b=a; ), and the object contains
dynamic variables.
- 1
- A reference to the same type as the object itself.
- There is no return type since it is a constructor.
Last updated : 26 July 2000 12.41pm