4
我有以下代码:集装箱
#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];
}
在VS编译2005年快递和2010年快递提供了以下错误:
error C2676: binary '*' : 'fixed' does not define this operator or a conversion to a type acceptable to the predefined operator
如果我取消任何主要三行(注释额外的向量),它会编译。如果我使用gcc,它会编译。任何人都可以给出一个暗示为什么这是什么?
该代码是一个大型项目的简化版本,所以这三种解决方案不幸都不适合我。
环境我试过的是使用gcc的Qt,但是猜测它没有相同的头文件。我已经报告了该错误: https://connect.microsoft.com/VisualStudio/feedback/details/637760/container-of-template-class-with-automatic-conversion-problem – 2011-01-24 07:49:19