Define a Class for Matrix Manipulation (3)

  1. Modify your previous exercise about class CMatrix and add a copy constructor.
  2. When you tried to declare the parameter of this copy constructor as a const reference parameter (as suggested in P.405), you might encounter an error message like This is because that C++ compiler cannot make sure whether the member functions Get() invoked in this constructor will modify the value of any data members.
  3. You need to tell the compiler that Get() will not alter the value of any data members. By declaring the member function to be const (as described in PP.393-394), the compiler will verify and enforce this rule.

Test your class definition with this main program. Save your class definition in "matrix.h" and compile the program with "g++ matrix-3.cpp". The running result should look like:


Copy constructor called.
 1 1 1
 1 1 1
 1 1 1
 88  1  1
  1  1  1
  1  1  1