C++快速地板模板:Windows上的Visual Studio出现C4430错误

C++ fast floor templates: C4430 Error with Visual Studio on Windows

本文关键字:Studio Visual 出现 错误 C4430 上的 C++ Windows      更新时间:2023-10-16

我正在尝试为快速楼层创建一个模板。

我有一个模板的以下开头,但在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和double)。我正在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 Studio尝试同样的方法时,我最终会出现上面的错误。

谢谢!

它在VS2013和VS2010上只使用#include <cmath>搜索/将i32替换为intf64替换成double。这让我怀疑INOUT在某个地方与某些预处理器定义发生冲突。例如,如果将模板类型重命名为TU,是否适用?