friend templates in gcc-2.8.0 & egcs-1.0.1
Levente Farkas
!spam-lfarkas@ohsh.u-szeged.hu
Thu Jan 29 16:16:00 GMT 1998
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
---------------------------------------------------------------------
More information about the Gcc
mailing list