You are unlikely to be doing it very often, but if you do pass objects of a reference class type to a function by value, you must implement a public copy constructor; this situation can arise with the Standard Template
Library implementation for the CLR, which you will learn about in Chapter 10.
The parameter to the copy constructor must be a const reference, so you would defi ne the copy constructor for the Box class like this:
Box(const Box% box) : Length(box.Length), Width(box.Width), Height(box.Height)
{ }
In general, the form of the copy constructor for a ref class T that allows a ref type object of type T to be passed by value to a function is:
T(const T% t)
{
// Code to make the copy...
}
Occasionally, you may also need to implement a copy constructor that takes an argument that is a handle. Here ’ s how you could do that for the Box class:
Box(const Box^ box) : Length(box- > Length), Width(box- > Width), Height(box- > Height)
{}
As you can see, there is little difference between this and the previous version.