ideone错误的输出c ++

时间:2015-10-14 15:43:46

标签: c++ compiler-errors

为什么输出错误?

http://ideone.com/0hCkRp

#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();
}

虽然这个是正确的吗?

http://ideone.com/kUrBTE

#define ul unsigned
namespace my_const{
    const ul decimal_accuracy_10 = 100;//change rhs to 100 -> works fine
};

只需改变100即可使其完美运行。为什么呢?

0 个答案:

没有答案