Template compilation problem

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Dear VC++ experts,

--------------------------------------- This:
template <int L, int M, int T>
class Quantity
{
public:
 Quantity(double = 0) {}
 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); // line 8
};

template<int L1, int M1, int T1, int L2, int M2, int T2>
Quantity<L1+L2,M1+M2,T1+T2> operator*
 (const Quantity<L1,M1,T1>& q1, const Quantity<L2,M2,T2>& q2) // line 13
{
    Quantity<L1+L2,M1+M2,T1+T2> q;
    return q;
}

typedef Quantity<1,0,-2> Acceleration;
typedef Quantity<1,0,0> Length;

const Acceleration GRAV(9.81);
const Length penLen(1);

int main()
{
Quantity<2,0,-2> q = penLen * GRAV; // line 27
}
-------------------------------------------
does not compile with VC++ v8b2, saying the darndest thing:
~~~~~~~~~~~~~~~~~~~
..\test.cpp(27) : error C2593: 'operator *' is ambiguous
.\test.cpp(8): could be
'Quantity<L,M,T> operator *<1,0,0,1,0,-2>(const Quantity<1,0,0> &,
const Quantity<1,0,-2> &)'
[found using argument-dependent lookup]
with
[
L=2,
M=0,
T=-2
]
.\test.cpp(13): or
'Quantity<L,M,T> operator *<1,0,0,1,0,-2>(const Quantity<1,0,0> &,
const Quantity<1,0,-2> &)'
with
[
L=2,
M=0,
T=-2
]
while trying to match the argument list '(const Length, const Acceleration)'
~~~~~~~~~~~~~~~~~~~~~
How is it ambiguous if the two reported are the same? Is that their
ADL implementation contributing to this nonsense?


Any comment is mightily appreciated.

BTW, Comeau online compiles it without a problem.

V
.



Relevant Pages

  • Re: GCC difference in size of long int on Suse SLES9 / Suse Professional 10.0
    ... The kernel uses printf() with 'long int', ... I can't compile 'on-the-fly'. ... clashing with the hardware and any libs that you interact with. ... platform types build up their own int types. ...
    (comp.os.linux.development.apps)
  • Re: Im a C++ programmer, and Relfs X.CPP is good.
    ... >> and it doesn't compile either. ... home.cpp:93: implicit declaration of function `int fclose' ... You cannot change to your home directory through an external ...
    (comp.lang.lisp)
  • Re: Im a C++ programmer, and Relfs X.CPP is good.
    ... >> and it doesn't compile either. ... home.cpp:93: implicit declaration of function `int fclose' ... You cannot change to your home directory through an external ...
    (comp.unix.programmer)
  • Re: non-static context
    ... public MyStatic(int length, int width) { ... Within the MyStatic constructor method, a local variable named area is ... This version of class MyStatic won't compile. ...
    (comp.lang.java.help)
  • Re: new order doubt
    ... Warning test2.c: 8 no type specified. ... Defaulting to int ... Tests probably come in several different types: this should compile ... Even Microsoft has problems with this obscure rules. ...
    (comp.lang.c)