|
Boost Users : |
Subject: Re: [Boost-users] [units] User-defined vector class template won'tcompile
From: Terry Golubiewski (tjgolubi_at_[hidden])
Date: 2010-05-27 23:14:49
Your reply provided the key, thank you.
I misunderstood what multiply_typeof_helper was for. It's like common_type<> in C++0X, but its more specialized for each kind of operator.
Which is obviously important for units.
My program compiles and runs now. Thanks again.
terry
BTW, the return statement is not recursive, because it swaps the lhs and rhs.
// vector * T
template<int Dim, class T1, class T2> inline
typename boost::units::multiply_typeof_helper<T2, vector<Dim, T1> >::type
operator*(const vector<Dim, T1>&lhs, const T2& rhs)
{ return rhs * lhs; }
Since multiply_typeof_helper<T1,T2> is really just a glorified version of typeof(T1()*T2()), what you're saying here is that the return type of the product of a vector and a scalar is the return type of the product of a vector and a scalar. You need to define the top-level multiply operation; define it something like this :
// vector * T
template<int Dim, class T1, class T2> inline
vector<Dim,typename boost::units::multiply_typeof_helper<T2, T1 >::type>
operator*(const vector<Dim, T1>&lhs, const T2& rhs)
{ //return rhs * lhs; this return statement is also wrong, since it is recursive, defining the returned value in terms of the operator itself...}
Cheers,
Matthias
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net