We’ve seen two ways to initialize objects. A no–argument constructor can initialize data members to constant values, and a multi–argument constructor can initialize data members to values passed as arguments. Let’s mention another way to initialize an object: you can initialize it with another object of the same type. Surprisingly, you don’t need to create a special constructor for this; one is already built into all classes. It’s called the default copy constructor. It’s a one–argument constructor whose argument is an object of the same class as the constructor. The ECOPYCON program shows how this constructor is used.
Tuesday, November 4, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment