From mboxrd@z Thu Jan 1 00:00:00 1970 From: Levente Farkas To: Alexandre Oliva , egcs@cygnus.com Subject: Re: friend templates in gcc-2.8.0 & egcs-1.0.1 Date: Sat, 31 Jan 1998 02:48:00 -0000 Message-id: References: X-SW-Source: 1998-01/msg01173.html On 31-Jan-98 Alexandre Oliva wrote: > This should be in the FAQ list. Jeff, would you put this in? > > Levente Farkas writes: > >> n_vector.h:69: warning: friend declaration `class N_Vector operator >> *(const >> T &, const class N_Vector &)' >> n_vector.h:69: warning: will not be treated as a template instantiation >> n_vector.h:69: warning: unless you compile with -fguiding-decls >> n_vector.h:69: warning: or add <> after the function name > > In order to make a specialization of a template function a friend of a > (possibly template) class, you must explicitly state that the friend > function is a template, by appending angle brackets to its name, and > this template function must have been declared already. An error in > the last public comment draft of the ANSI/ISO C++ Standard has led > people to believe that was not necessary, but it is, and it was fixed > in the final version of the Standard. > > Which means you must declare operator* as a template function, before > it is referred to, but then you must have declared the class template > too, as follows: > > template class N_Vector; > template inline N_Vector operator*(const T&, const > N_Vector&); > > Now you may define N_Vector: > >> template >> class N_Vector : public Vector >> { >> public : >> ... >> N_Vector operator * (const T &) const; > but you must add angle brackets when you refer to a template function: >> //friend N_Vector operator * > friend N_Vector operator * <> >> (const T &, const N_Vector &); >> } >> ... > > and then you can define the template function: > >> template >> inline N_Vector >> operator *(const T & Scalar, const N_Vector & V) >> { >> return V * Scalar; >> } >> -------------------- thanks for it, but 1, from where can I know things like that ? 2, if I modify the program this way, than it's no longer works on all other unix system (Solaris, AIX) even with gcc (but "older" version 2.7.2) and I'm not the sysadm everywhere. So is there any backward compatible solution ??? or I can't use egcs :-( or redesign our project (in this case friend is unnecessary, but..):-( -- Levente --------------------------------------------------------------------- E-Mail: Levente Farkas Homepage: http://www.inf.u-szeged.hu/~lfarkas/ PGP public key & Geek Code: !spam-lfarkas@anna.inf.u-szeged.hu This message was sent by XF-Mail, Date: 31-Jan-98 Time: 11:31:58 ---------------------------------------------------------------------