P
pikalaw
Need help figuring out why the following code fails to compile:
#include <complex>
#include <boost/rational.hpp>
int main()
{
using namespace std;
using namespace boost;
complex<rational<int> > z;
const complex<rational<int> > j(0,1);
z = 3 + 2 * j; // (1). won't
compile. complains about no matching operator*.
z = 3 + rational<int>(2) * j; // (2). but this works.
note the explicit conversion.
return 0;
}
The compiler error, generated by gcc version 4.0.1 (Apple Inc. build
5490), was
boost/operators.hpp:251: note:
candidates are: boost::rational<int> boost:perator*(const
boost::rational<int>&, const int&)
boost/operators.hpp:251: note:
boost::rational<int> boost:perator*(const int&, const
boost::rational<int>&)
boost/operators.hpp:251: note:
boost::rational<int> boost:perator*(const
boost::rational<int>&, const boost::rational<int>&)
What bugs [pun] me is why didn't the compiler try the operator
std::complex<boost::rational<int> >
std:perator*(
const boost::rational<int>&,
const std::complex<boost::rational<int> >&)
for (1) by promoting the integer constant 2 to rational<int>? But if
I explicitly convert it as in (2), then it finds this operator.
Please illuminate me!
#include <complex>
#include <boost/rational.hpp>
int main()
{
using namespace std;
using namespace boost;
complex<rational<int> > z;
const complex<rational<int> > j(0,1);
z = 3 + 2 * j; // (1). won't
compile. complains about no matching operator*.
z = 3 + rational<int>(2) * j; // (2). but this works.
note the explicit conversion.
return 0;
}
The compiler error, generated by gcc version 4.0.1 (Apple Inc. build
5490), was
boost/operators.hpp:251: note:
candidates are: boost::rational<int> boost:perator*(const
boost::rational<int>&, const int&)
boost/operators.hpp:251: note:
boost::rational<int> boost:perator*(const int&, const
boost::rational<int>&)
boost/operators.hpp:251: note:
boost::rational<int> boost:perator*(const
boost::rational<int>&, const boost::rational<int>&)
What bugs [pun] me is why didn't the compiler try the operator
std::complex<boost::rational<int> >
std:perator*(
const boost::rational<int>&,
const std::complex<boost::rational<int> >&)
for (1) by promoting the integer constant 2 to rational<int>? But if
I explicitly convert it as in (2), then it finds this operator.
Please illuminate me!