为什么输出错误?
#define ul unsigned
namespace my_const{
const ul decimal_accuracy_10 = pow(10, 2);//change rhs to 100 -> works fine
};
struct Vector2D{
int x[2];
Vector2D(float a, float b){
x[0] = a*my_const::decimal_accuracy_10;
x[1] = b*my_const::decimal_accuracy_10;
}
Vector2D(){}
inline void print(){
cout << "\n" << (float)x[0] / 100.0f << " " << x[1] / 100.0f << "\n";
}
};
int main()
{
Vector2D my(0.01f, 0.02f), ball(0.03f, 0.04f);
my.print();
}
虽然这个是正确的吗?
#define ul unsigned
namespace my_const{
const ul decimal_accuracy_10 = 100;//change rhs to 100 -> works fine
};
只需改变100即可使其完美运行。为什么呢?