By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,864 Members | 1,293 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,864 IT Pros & Developers. It's quick & easy.

Error when overloading << in template

P: n/a
Hi, as many others im making my own matrix class, but the compiler is
giving me a lot of errors related to the friend functions which
overload >> and <<.I've looked around and no one seems to get the same
error. Here is the code of the class template< class T > class Matrix
{ friend ostream &operator << <>( ostream &, const Matrix< T >
& ); friend istream &operator >> <>( istream &, Matrix< T > &
); public: Matrix( int = 3, int = 3 ); Matrix( const
Matrix< T > & ); ~Matrix(); private: int r_size,
c_size; T **ptr; }; and here the definition for ostream
&operator << and istream &operator >> //cout template< class T >
ostream &operator << ( ostream &output, const Matrix< T > &m ) {
int i, j; for( i = 0; i < m.r_size; i++ ) {
for( j = 0; j < m.c_size; j++ ) {
output << m.ptr[ i ][ j ] << " "; }
output << endl; } return output; } //cin template<
class T > istream &operator >> ( istream &input, Matrix< T > &m ) {
int i, j; for( i = 0; i < m.r_size; i++ ) {
cout << "Introduzca los elementos de la fila " << i << " separados por
espacios\n"; for( j = 0; j < m.c_size; j++ )
input >> m.ptr[ i ][ j ]; } return
input; } Errors given by the compiler error: el id de plantilla
'operator<< <>' para 'std::basic_ostream<char,
std::char_traits<char> >& operator<<(std::basic_ostream<char,
std::char_traits<char> >&, const Matrix<int>&)' no coincide con
ninguna declaración de plantilla error: el id de plantilla
'operator>><>' para 'std::basic_istream<char,
std::char_traits<char> >& operator>>(std::basic_istream<char,
std::char_traits<char> >&, Matrix<int>&)' no coincide con ninguna
declaración de plantilla Im spanish so maybe a small spanish class
will be helpfull for most readers of this group plantilla == template
no coincide con ninguna declaracion de == does not coincide with any
declaration of Also when a try to use the overloaded operators in main
a get another error which tells that the private members of class
Matrix are private in that context. Thanks

Apr 9 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Sorry its the first time i post in google groups and something went
wrong.

If an administrator sees this please remove the post, and ill try to
make it better next time

Apr 9 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.