This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
specialization of template friends
- From: W_Guthrie <pontusmelke at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Wed, 7 Nov 2007 02:19:41 -0800 (PST)
- Subject: specialization of template friends
Hi!
I have the following problem: I have written a Vector-class which looks
somewhat like this
template <int T> class Vector;
template <int T> double dot(const Vector<T>& u, const Vector<T>& v);
template<int T>
class Vector {
Vector& operator+=(const Vector& v);
...
friend double dot <>(const Vector<T>& u, const Vector<T>& v);
};
Now I want add a cross-product which only is a friend of Vector<3>, how do I
do this? I had one solution which looked like this:
template<int T>
class Vector {
Vector& operator+=(const Vector& v);
...
friend double dot <>(const Vector<T>& u, const Vector<T>& v);
friend Vector<3> cross(const Vector<T>& u, const Vector<T>& v);
};
But this only works if I compile with -O3 or explicitly make the function to
an inline function? Does anyone know why this is? How should one do this?
Please let me know!
/Woodie
--
View this message in context: http://www.nabble.com/specialization-of-template-friends-tf4763774.html#a13624507
Sent from the gcc - Help mailing list archive at Nabble.com.