在用作模板参数的类的成员函数中,我有一个包含以下代码的函数:
double x = /*Something operation returning double*/;
x /= CubeWidth; /*CubeWidth is a class member*/
cout << "Element after centering and normalization = " << x << endl;
cout << "and after adding 1 and truncating = " << x+1 << endl;
cout << "then static cast = " << (int) x+1 << endl;
这个函数的输出是
Element after centering and normalization = 1
and after adding 1 and truncating = 2
then static cast = 1
显然,最后一行应该给出答案 2。
如果我实例化完全相同的类而不使用它作为模板参数,我不会得到这个打印输出,而是我有正确的一个。
谁能告诉我为什么会这样?