我正试图为快速楼层创建一个模板。
下面是一个模板的开头,但是在Windows下编译时,我收到了一个错误,与我的代码中IN和OUT的使用有关。任何帮助都将不胜感激。提前感谢!
template<typename IN, typename OUT>
class FastConversion {
public:
FastConversion() {
// empty
}
// rounds to the next lowest whole number
// 1.5 --> 1.0
// -1.5 --> -2.0
inline OUT floor(const IN& x) {
OUT output = 0;
// slowest version
#if defined(__APPLE__) || defined(__linux__) || defined(WIN64)
output = static_cast<OUT>(std::floor(static_cast<double>(x)));
#elif defined(WIN32)
__asm {
fld x;
fadd st, st(0);
fadd negOneHalf;
fistp i;
sar i, 1;
};
#else
output = static_cast<OUT>(std::floor(static_cast<double>(x)));
#endif
return output;
}
};调用如下:
inline i32 fastFloor(f64 x) {
FastConversion<f64, i32> f;
i32 floored = f.floor(x);
return floored;
}注意: i32和f64如预期的那样(int和f64)。我在64位机器上运行32位编译。我用的是C++-11。我有一个CMake文件和一个vcxproj文件。
以下错误:
FastConversion.h(40): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int我似乎可以在mac上使用clang编译得很好,但当我尝试使用Visual进行同样的编译时,最终会出现上述错误。
谢谢!
发布于 2014-09-24 13:59:10
它在VS2013和VS2010上编译得很好,只使用#include <cmath>和搜索/用int替换i32,用double替换f64。这让我怀疑IN和OUT与某个预处理器定义有冲突。例如,如果您将模板类型重命名为T和U,那么它对您有用吗?
https://stackoverflow.com/questions/26009237
复制相似问题