Define a Class for Matrix Manipulation (3)
-
Modify your previous exercise about
class CMatrix and add a
copy constructor (P.317).
- When you tried to declare the parameter of this copy constructor as
a const reference parameter (as suggested in P.317), you might encounter
an error message like
- error: member function 'Get' not viable: 'this' argument has
type 'const CMatrix', but function is not marked const
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.
- 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 P.307), 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
"clang++ 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