![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
help on how to reload ostream operator in a template classHello everyone,
I am trying to learn C++ by myself. Well, I might be too old to learn a computer language. I need a hand to write a matrix library for a simulation. My question is how to reload the ostream operator << in a template the class. I tried the following way, but it didnt work: 1. CPP / C++ / C Code:
Last edited by LuciWiz : 08-Feb-2005 at 14:20.
|
|||
|
#2
|
||||
|
||||
|
I'd be happy to help, if you could also provide the error message that your compiler issues in response to this code. If there are any other portions of code that might be relevant, such as #include statements, please include those lines as well.
One more note: this forum supports special tags for posting C/C++ code samples, which highlight the languages' syntactical constructs and produce a more readable example. Like this: CPP / C++ / C Code:
To start the code sample, use the tag [c++ ], without the extra space I inserted before the closing brace. To end it, use [/c++ ]. Matthew |
|
#3
|
|||
|
|||
|
Thanks a lot, Matthew.
Here is the code: CPP / C++ / C Code:
error message: vec.h:20: error: declaration of `class T' vec.h:6: error: shadows template parm `class T' thanks, |
|
#4
|
||||
|
||||
|
eggie,
The error message indicates that there is a conflict between the friend declaration CPP / C++ / C Code:
CPP / C++ / C Code:
Some compilers will not complain about your code, but according to the specification for Standard C++, you may not redeclare a template parameter. By typing "template<class T>" again inside the class declaration, you are redeclaring the symbol "T". I don't know if this explanation makes much sense, but one solution is to change your friend declaration to the following: CPP / C++ / C Code:
Feel free to ask further questions. Matthew P.S. Most often, you will see the term "overloading" used to refer to the type of polymorphism in your code. ![]() |
|
#5
|
|||
|
|||
|
Thank you so much, my friend.
|
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| non-member function question | crq | C++ Forum | 1 | 03-Feb-2005 22:59 |
| What is "Ambigious symbol" ??*( a compilation error) | small_ticket | C++ Forum | 2 | 07-Jan-2005 22:10 |
| Error C2146: syntax error : missing ',' before identifier 'C4' | mattchew008 | C++ Forum | 2 | 19-Dec-2004 07:06 |
| hashing help | saiz66 | C++ Forum | 1 | 06-Jul-2004 07:16 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The