I have the following code:
#include <vector> template<int Wt = 0> class fixed { public: explicit fixed(double val = 0) { operator=(val); } ~fixed(){} operator double() const { return v_; } double operator =(const double &d){ if (d>Wt) v_ = Wt; else v_ = d; return v_; } private: double v_; }; int main(){ fixed<5> x; std::vector<fixed<6> > v(5); //std::vector<fixed<6> > v(5,0); //fixed<6> y; //v[0] = 0; x = x*v[0]; }
Compiling in VS 2005 Express and 2010 Express gives the following error:
error C2676: binary '*': 'fixed' does not define this operator or conversion to a type acceptable for a predefined operator
If I uncomment any of the three lines in the main one (commenting on an additional vector), it will compile. If I use gcc, it will compile. Can someone give a clue why this is?
The code is a simplified version of a larger project, so the three solutions, unfortunately, are not options for me.
source share