This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: c++ template class problem
Hi.
: On which platform? I can't reproduce this problem with the latest
: snapshot of egcs on sparc-sun-solaris2.5.
Thank you for reply. I forgot to write it. It is Linux/Alpha (alphaev5-linux).
: BTW, you must declare the template function before you refer to it, as
: suggested in the FAQ (the answer for friend templates was recently
: updated; please take a look at it).
I added one line of declaration as the following and tried. But, result
is same as before. Is the way of delclaration wrong ?
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
石井俊直 Toshinao Ishii
Advanced Technology R&D Center (ATC) 三菱電機(株)
Mitsubishi Electric Corporation 先端技術総合研究所
email: ici@qua.crl.melco.co.jp (NeXTMail/MIME Welcome)
fax: +81-6-497-7288
------------------------------------------------------------------------
#include <iostream.h>
template <class T> class C;
template <class T> ostream& operator << ( ostream &os, const C<T>& c );
template <class T> class C
{
public:
T v;
C() { v = 0; }
~C() {}
friend ostream& operator << <>( ostream &, const C<T>& );
};
template <class T>
ostream& operator << ( ostream &os, const C<T>& c )
{
os << c;
return os;
}
int main()
{
C<double> tcd;
tcd.v = 3.14;
cout << tcd << endl;
}