Advanced OOP Frequently Asked Questions (FAQ)

Q.Is there a newsgroup to support C++?
Q. When a constructor is called that takes arguments, does the default constructor still get called?
Q. Why does the copy constructor definition have a same-class reference parameter?
 


Q. Is there a news group to support C++?

A. Look for comp.lang.c++.


Q. When a constructor is called that takes arguments, does the default constructor still get called?

A. No.


Q. Why does the copy constructor definition have a same-class reference parameter?

A. Simple put, that is the definition of the copy constructor. If it didn't have a parameter of a same-class reference, then it would be another type of constructor. What makes the copy constructor special is that when a copy of an object is needed, the copy constructor is invoked to construct it. For example:

void Foo( MGString X ); // Pass by value, copy constructor called

void Foo( MGString& X ); // Pass by reference, copy constructor not called

In the first form, since it uses pass-by-value syntax (as in C), the a copy of the original parameter must be made and passed to the function. The copy constructor is invoked to create that copy.