C++ C++;快速地板模板:Windows上的Visual Studio出现C4430错误
我正在尝试为快速楼层创建模板 我有一个模板的以下开头,但在Windows下编译时收到一个错误,与代码中的IN和OUT的使用有关。任何帮助都将不胜感激。提前谢谢C++ C++;快速地板模板:Windows上的Visual Studio出现C4430错误,c++,templates,c++11,visual-studio-2013,C++,Templates,C++11,Visual Studio 2013,我正在尝试为快速楼层创建模板 我有一个模板的以下开头,但在Windows下编译时收到一个错误,与代码中的IN和OUT的使用有关。任何帮助都将不胜感激。提前谢谢 template<typename IN, typename OUT> class FastConversion { public: FastConversion() { // empty } // rounds to the next lowe
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;
}
};
在mac上使用clang似乎可以很好地编译,但当我尝试在Visual Studio上使用clang时,我最终会出现上述错误
谢谢 它在VS2013和VS2010上编译得很好,只需使用
#include
和搜索/替换i32为int和f64为double。这让我怀疑IN和OUT与某个预处理器定义冲突。例如,如果您将模板类型重命名为T
和U
,是否对您有效?类定义中有两个未定义的变量:negOneHalf
和i
。当我定义这些和typedef int i32;typedef双f64
你的代码在VC++2010上编译时没有错误。只是一个附带问题,是什么让这个转换很快?它在VS2013和VS2010上编译得很好,只需使用\include
和搜索/替换i32
为int
和f64
为double
。这让我怀疑IN
和OUT
与某个预处理器定义冲突。例如,如果您将模板类型重命名为T
和U
,是否对您有效?@AndyBrown:这一定是命名冲突。T/U工作正常。谢谢如果您想添加答案,我将稍等汉克斯·布莱恩,我把这条评论复制成了一个答案,这样以后谷歌用户就更容易找到了。
inline i32 fastFloor(f64 x) {
FastConversion<f64, i32> f;
i32 floored = f.floor(x);
return floored;
}
FastConversion.h(40): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int