public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Levente Farkas <!spam-lfarkas@ohsh.u-szeged.hu>
To: Alexandre Oliva <oliva@dcc.unicamp.br>, 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	[thread overview]
Message-ID: <XFMail.980131114114.!spam-lfarkas@ohsh.u-szeged.hu> (raw)
In-Reply-To: <orhg6l5s7t.fsf@amazonas.dcc.unicamp.br>

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<T> operator
>> *(const
>> T &, const class N_Vector<T> &)'
>> 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 T> class N_Vector;
> template <class T> inline N_Vector<T> operator*(const T&, const
> N_Vector<T>&);
> 
> Now you may define N_Vector:
> 
>> template <class T>
>> class N_Vector : public Vector<T>
>> {
>>   public :
>>   ...
>>  N_Vector<T>   operator * (const T &) const;
> but you must add angle brackets when you refer to a template function:
>>  //friend N_Vector<T> operator *
>    friend N_Vector<T> operator * <>
>>  (const T &, const N_Vector<T> &);
>> }
>>  ...
> 
> and then you can define the template function:
> 
>> template <class T>
>> inline N_Vector<T> 
>> operator *(const T & Scalar, const N_Vector<T> & 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 <!spam-lfarkas@ohsh.u-szeged.hu>
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
---------------------------------------------------------------------

  reply	other threads:[~1998-01-31  2:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-01-29 16:16 Levente Farkas
1998-01-30 17:54 ` Alexandre Oliva
1998-01-31  2:48   ` Levente Farkas [this message]
1998-01-31 12:16     ` Alexandre Oliva
1998-01-31 13:14       ` Mumit Khan
1998-01-31 13:02     ` Mumit Khan
1998-02-08  0:14   ` Jeffrey A Law

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='XFMail.980131114114.'\!'spam-lfarkas@ohsh.u-szeged.hu' \
    --to=!spam-lfarkas@ohsh.u-szeged.hu \
    --cc=egcs@cygnus.com \
    --cc=oliva@dcc.unicamp.br \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).