public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alexandre Oliva <oliva@dcc.unicamp.br>
To: Oleg Krivosheev <kriol@fnal.gov>
Cc: Joe Buck <jbuck@synopsys.com>, egcs team <egcs@cygnus.com>
Subject: Re: something wrong with template instantiation mechanics
Date: Fri, 10 Oct 1997 20:46:00 -0000	[thread overview]
Message-ID: <orra9t2cgi.fsf@sunsite.dcc.unicamp.br> (raw)
In-Reply-To: <Pine.GSO.3.96.971010134118.7378A-100000@drabble>

Oleg Krivosheev writes:

> template <class T> class X {

Here, you declare a non-template operator+ :

>     friend X<T> operator+( const X<T>&, const X<T>& );

> };

And here, you declare a define a template one:

> template <class T> X<T>
> operator+( const X<T>& a, const X<T>& b ) {
>   return X<T>( a.t_ + b.t_ );
> }

And here, overload resolution chooses the non-template one.

>   x = x+y;

> as one can see, op+ is not instantiated.

It shouldn't, since it is not used at all.  The non-template operator+
you use, OTOH, is not defined.  You should have declared the template
version of the function friend, like this:

template <typename T>
class X;
template <typename T>
X<T> operator+(const X<T>&, const X<T>&);

template <typename T>
class X {
// note the angle brackets:
//                     vv
  friend X<T> operator+<>(const X<T>&, const X<T>&);
};

-- 
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil

  reply	other threads:[~1997-10-10 20:46 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <3439FE5B.53F1D3CC.cygnus.egcs@msu.ru>
1997-10-07  3:15 ` AIX & shared libstdc++ Jason Merrill
1997-10-07  3:48   ` Andrey Slepuhin
1997-10-09  9:26   ` Andrey Slepuhin
1997-10-09 15:14     ` Ian Lance Taylor
1997-10-13  5:05       ` Andrey Slepuhin
1997-10-09 16:31     ` something wrong with template instantiation mechanics Oleg Krivosheev
1997-10-10  8:51       ` Joe Buck
1997-10-10  8:51       ` Joe Buck
1997-10-10  8:51         ` Oleg Krivosheev
1997-10-10  8:51           ` Oleg Krivosheev
     [not found]           ` <Pine.GSO.3.96.971009232426.6908A-100000.cygnus.egcs@drabble>
1997-10-10 11:44             ` Jason Merrill
1997-10-10 17:21               ` Oleg Krivosheev
1997-10-10 17:19                 ` Jason Merrill
1997-10-10 11:46         ` Oleg Krivosheev
1997-10-10 20:46           ` Alexandre Oliva [this message]
     [not found] <orbu0tza3m.fsf@sunsite.dcc.unicamp.br>
1997-10-13 13:41 ` Oleg Krivosheev

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=orra9t2cgi.fsf@sunsite.dcc.unicamp.br \
    --to=oliva@dcc.unicamp.br \
    --cc=egcs@cygnus.com \
    --cc=jbuck@synopsys.com \
    --cc=kriol@fnal.gov \
    /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).