During compilation, I get a slew of errors whenever I perform
this operation:
-- the overloaded operator<< non-member method is:
-- the member method Transpose( ) [ transposes the calling object by
moving values into a temp Matrix object and then assignin it to the
calling object] is:
-- errors: [including quite a few more it won't let me post but they all
deal with the << operator]
However, the code functions correctly with this set of commands:
Does anyone have any idea as to why the first method produces so many errors concerning the ostream << operator? I thought it may have something to do with the const-ness of the method but I am not allowed to change the Transpose( ) method so that it returns a const Matrix object. Anybody have any input?
this operation:
Code:
cout << aMatrix.Transpose( ) << endl;
Code:
ostream & operator<<( ostream & out, const Matrix & matrixRHS )
moving values into a temp Matrix object and then assignin it to the
calling object] is:
Code:
void Transpose( void );
deal with the << operator]
Code:
Test.cpp:32: error: no match for ‘operator<<’ in ‘std::cout << aMatrix. Matrix::Transpose()’ /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/ostream.tcc:67: note: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>& (*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/ostream.tcc:78: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/ostream.tcc:90: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/ostream.tcc:125: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char, _Traits = std::char_traits<char>]
However, the code functions correctly with this set of commands:
Code:
aMatrix.Transpose( ) ; cout << aMatrix << endl;
Comment