This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]