public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* friend templates in gcc-2.8.0 & egcs-1.0.1
@ 1998-01-29 16:16 Levente Farkas
  1998-01-30 17:54 ` Alexandre Oliva
  0 siblings, 1 reply; 7+ messages in thread
From: Levente Farkas @ 1998-01-29 16:16 UTC (permalink / raw)
  To: egcs

hi,
[may be this's not the proper place for my question, but...]
I'm just upgrade to egcs-1.0.1 and try to recompile my project, which
contain the following segment of code for numeric vector in n_vector.h :
---------------------
template <class T>
class N_Vector : public Vector<T>
{
  public :
  ...
 N_Vector<T>   operator * (const T &) const;
 friend N_Vector<T> operator *(const T &, const N_Vector<T> &);
}
 ...
template <class T>
inline N_Vector<T> 
operator *(const T & Scalar, const N_Vector<T> & V)
{
  return V * Scalar;
}
--------------------
and there is templates.cc for in instantiation with :
--------------------
...
template inline N_Vector<double> operator *(const double &, const
N_Vector<double> &);
--------------------
this is work since gcc 2.6.x- 2.7.2 (-fno-implicit-templates) compiled, 
but after the upgrade to egcs-1.0.1 I've got the following warning during
compilation :
--------------------
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
--------------------
but no error, but at link-time (many similar) :
--------------------
impedance.o:/home/lfarkas/ssa/impedance.cc:617: more undefined references to
`operator*(double const &, 
N_Vector<double> const &)' follow
collect2: ld returned 1 exit status
make: *** [ssa] Error 1
--------------------

so my question what is the problem ? and what's the solution ?
this is a quote from  1997 C++  Standard Public Review :
--------------------
 14.5.3  Friends                                          [temp.friend]

1 A friend function of a class template can be a function template or an
  ordinary (non-template) function.  [Example:
          template<class T> class task {
              // ...
              friend void next_time();
              friend task<T>* preempt(task<T>*);
              friend task* prmt(task*);           // task is task<T>
              friend class task<int>;
              // ...
          };
  Here,  next_time()  and  task<int> become friends of all task classes,
  and each task has appropriately typed functions preempt()  and  prmt()
  as  friends.   The preempt functions might be defined as a template as
  follows
          template<class T> task<T>* preempt(task<T>* t) { /* ... */ }
--------------------

ps. please replay to my private address too.

-- 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: 29-Jan-98  Time: 17:01:04
---------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~1998-02-08  0:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-01-29 16:16 friend templates in gcc-2.8.0 & egcs-1.0.1 Levente Farkas
1998-01-30 17:54 ` Alexandre Oliva
1998-01-31  2:48   ` Levente Farkas
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

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).