473,396 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Error when overloading << in template

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
1 2105
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Steven T. Hatton | last post by:
The comperable operator*() to that shown here works for a non-template class: template <typename T> inline Vector3<T> operator*(const Vector3<T>& v, const T& n) { Vector3<T> t(v); return t *=...
10
by: pmatos | last post by:
Hi all, I have the following code: class test { public: test(const std::string *n) : name(n) {} virtual ~test() {} const std::string * getName() { return name; }
4
by: hall | last post by:
Hi all. I have run into a problem of overloading a templatized operator>> by a specialized version of it. In short (complete code below), I have written a stream class, STR, which defines a...
3
by: Suresh Tri | last post by:
Hi all, I was trying to overload '<' operator for (varchar,varchar). But in the function which handles the comparision I want to use the previous '<' operator.. but it is going into a recursion....
29
by: v4vijayakumar | last post by:
Why there is no overloading (function and operator), function templates and exception handling support in c? after all these are all useful programming constructs. What prevents ANSI/ISO...
7
by: AlanJSmith | last post by:
I am converting some C++ projects from 6 to vs2005 in one of the headers i have the code that follows this passage in which I get an error saying int default cant be assumed so i added...
2
by: Joseph Turian | last post by:
I have a class Feature defined, which is a kind of Vocab: template <class T, unsigned I> class Vocab : boost::totally_ordered<Vocab<T,I { public: Vocab(); Vocab(const T& t); template<typename...
8
by: mattias.nissler | last post by:
Hi! Here is a problem I ran into at work. The following example doesn't compile on gcc-4.1: struct cons_end {}; template<typename U,typename Vstruct cons { U elem; V tail;
10
by: ozizus | last post by:
I overloaded operator << for STL map successfully: template <typename T1, typename T2ostream & operator << (ostream & o, map <T1,T2& m) { //code } the code works like a charm. Now, I want...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.