C++快速地板模板:Windows上的Visual Studio出现C4430错误
C++ fast floor templates: C4430 Error with Visual Studio on Windows
我正在尝试为快速楼层创建一个模板。
我有一个模板的以下开头,但在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替换为int和f64替换成double。这让我怀疑IN和OUT在某个地方与某些预处理器定义发生冲突。例如,如果将模板类型重命名为T
和U
,是否适用?
相关文章:
- Visual Studio 2015:Extern "C" 和 "export" 关键字
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 试图在visual studio上用C++创建一个桌面应用程序
- 如何在MS Visual Studio 2019中运行QT UI
- 如何使用Visual Studio 2017在C++中为参数化对象数组使用唯一指针
- Visual Studio Code - C++ Debugger 無法啟動
- Visual Studio 2019:插入多个C++风格的单行注释
- Visual Studio Code "undefined reference to `WinMain@16'"
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- Visual Studio中的函数声明和函数定义问题
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- Visual Studio mkl_link_tool.exe链接错误
- Visual Studio(或任何其他工具)能否将地址解释为调用堆栈(boost上下文)的开头
- 不同的Visual Studio版本中缺少.dll
- 用Visual Studio在C++中嵌入Julia
- Visual Studio 2017循环自动向量化问题
- 有没有办法在远程设备上打开和编辑visual Studio 2017解决方案
- 尝试使用继承和模板实现CRTP.Visual Studio正在生成编译器错误
- Visual Studio在尝试读取resource.txt文件时崩溃
- Visual Studio 2017 不允许我创建 C++ 专用模板