It seems to be calling the default compiler generated copy constructor. I am guessing there are some subtelties to copy constructor and templated classes. Do I need to specify a separate copy constructor when the object templates are of the same type?
The above "copy constructor" is not a copy constructor.
The copy constructor is declared as:
Matrix( const Matrix<T>& rhs );
which is not the same thing as what you wrote.
If Y == T, then yes, your constructor is a copy constructor. However to the compiler the default copy constructor looks like a specialization that binds tighter than your constructor. Hence the compiler chooses
to call the default copy constructor.
Thanks everyone for the replies. I now understand that a proper copy constructor has to be defined.
I have just one follow up question. I also want to define a constructor where the RHS can have a implicit convertible type. So that I could convert between the data types (say between float and integers).
In this case, the compiler complains that it cannot access the private member m_rows for the RHS. I am a bit confused as to why this should be. If I access the member through some public function, it is ok. I am wondering why this should cause a problem and if there is something that I can do in the class definition that would make such an implicit conversion possible.