A
Atlas
Hi,
I implemented a template as:
template <int L, int M, int T>
class Quantity
{
.....
public:
friend Quantity operator*(const Quantity& q1,const Quantity& q2);
.....
};
when I tried to use it as:
////////////////
typedef Quantity<1,0,-2> Acceleration;
typedef Quantity<1,0,0> Length;
const Acceleration GRAV(9.81);
const Length penLen(1);
....=penLen * GRAV;
////////////////////
The compiler complained "no operator defined for Acceleration".
If the both oprands have the same L,M,T, it works. But how to deal with
it if they are different?
And the return value is another issue, because it will have another set
of L,M,T.
I tried the following:
template <int L1, int M1, int T1, int L2, int M2, int T2>
friend Quantity<L1+L2,M1+M2,T1+T2> operator*
(const Quantity<L1,M1,T1>& q1,const Quantity<L2,M2,T2>& q2)
{
Quantity<L1+L2,M1+M2,T1+T2> q;
..........
return q;
},
but failed with " error C2995: 'Quantity<L1*L2,M1*M2,T1*T2> operator
*(const Quantity<L1,M1,T1> &,const Quantity<L2,M2,T2> &)' : template
function has already been defined".
Thanks a lot.
I implemented a template as:
template <int L, int M, int T>
class Quantity
{
.....
public:
friend Quantity operator*(const Quantity& q1,const Quantity& q2);
.....
};
when I tried to use it as:
////////////////
typedef Quantity<1,0,-2> Acceleration;
typedef Quantity<1,0,0> Length;
const Acceleration GRAV(9.81);
const Length penLen(1);
....=penLen * GRAV;
////////////////////
The compiler complained "no operator defined for Acceleration".
If the both oprands have the same L,M,T, it works. But how to deal with
it if they are different?
And the return value is another issue, because it will have another set
of L,M,T.
I tried the following:
template <int L1, int M1, int T1, int L2, int M2, int T2>
friend Quantity<L1+L2,M1+M2,T1+T2> operator*
(const Quantity<L1,M1,T1>& q1,const Quantity<L2,M2,T2>& q2)
{
Quantity<L1+L2,M1+M2,T1+T2> q;
..........
return q;
},
but failed with " error C2995: 'Quantity<L1*L2,M1*M2,T1*T2> operator
*(const Quantity<L1,M1,T1> &,const Quantity<L2,M2,T2> &)' : template
function has already been defined".
Thanks a lot.