This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Question about template friends
- To: gcc@gcc.gnu.org
- Subject: Question about template friends
- From: Damian Menscher <menscher@uiuc.edu>
- Date: Tue, 24 Aug 1999 12:14:55 -0500 (CDT)
First, let me point out that I realize this is answered in the FAQ, but I
still can't figure it out.
I'm attempting to overload operator<< for a template class I've written.
Following the faq, I've done the following:
--- from quark.h ------------------
// Forward declaration of class
template <class NUMBER>
class Quark;
template <class NUMBER>
ostream& operator<< (ostream&, const Quark<NUMBER>);
template<class NUMBER=Real> // default to Real if no
type is given
class Quark {
.
.
.
//IO Functions
friend ostream& operator<< <> (ostream&, const Quark<NUMBER>&);
};
---------------------------------------
and then tried to instantiate it as follows:
--------from quark.C ------------------
template<class NUMBER>
ostream& operator<<(ostream& os, const Quark<NUMBER>& quark) {
os << "( ";
for (int counter=0; counter<NUMSPINS; counter++)
os << quark.data[counter] << " ";
os << ")" << flush;
return os;
}
//////////////////////////
// Template Instantiations
template class Quark<float>;
template class Quark<double>;
template ostream& operator<< (ostream&, const Quark<float>&);
template ostream& operator<< (ostream&, const Quark<double>&);
------------------------------------------
When compiling, I get the error message:
quark.h:46: template-id `operator <<<Real>' for `operator <<(ostream &,
const Quark<float> &)' does not match any template declaration
Could someone please tell me what's going on here, or point me to the
proper place to ask this question?
TIA,
Damian Menscher
--
--==## Grad. student & Sys. Admin. @ U. Illinois at Urbana-Champaign ##==--
--==## <menscher@uiuc.edu> www.uiuc.edu/~menscher/ Ofc:(217)333-0038 ##==--
--==## Physics Dept, 1110 W Green, Urbana IL 61801 Fax:(217)333-9819 ##==--