C++错误:"内联"只能出现在函数上
C++ error: 'inline' can only appear on functions
所以我被一个棘手的问题困住了,已经花了一个小时来调查了。
我有一个项目,其中有一些相当旧的c++代码,我需要添加一些c++ 11代码。该项目之前正在编译,所以可以肯定的是,这个问题是由我在CMakelist.txt中添加以下内容引起的:
set (CMAKE_CXX_STANDARD 11)
问题是由这些定义引起的:
#define lt(a, b) ( ((a) < -b) )
#define ge(a, b) (! ((a) < -b) )
#define le(a, b) ( ((a) <= b) )
#define gt(a, b) (! ((a) <= b) )
#define eq(a, eps) ( (((a) <= eps) && !((a) < -eps)) )
#define ne(a, eps) ( !eq(a,eps) )
这是我得到的错误:
/Users/bs/util.h:284:22: note: expanded from macro 'eq'
#define eq(a, eps) ( (((a) <= eps) && !((a) < -eps)) )
^
In file included from /Users/bs/geom.cc:35:
In file included from /Users/bs/coord.h:30:
In file included from /Users/bs/vronivector.h:6:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iostream:38:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__locale:15:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:678:12: error: 'inline' can
only appear on functions
static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[2]: *** [src/CMakeFiles/vroni.dir/geom.cc.o] Error 1
make[1]: *** [src/CMakeFiles/vroni.dir/all] Error 2
make: *** [all] Error 2
这里有什么问题,可以解决吗?
符号'eq'有名称冲突不幸的是,c风格的宏做了一个文字文本替换,所以与eq相关的文本被塞进语句中,你看到的错误信息产生如下所示:
static inline _LIBCPP_CONSTEXPR bool ( (((char_type __c1) <= eps) && !(char_type __c1) < -eps)) _NOEXCEPT
最好的解决方案是停止使用宏,并找到另一种方法来定义你的'eq' 'lt'等函数。
例如,你可以这样替换eq宏:template<typename T>bool eq(T a,T eps)
{
return (a <= eps && a >= -eps);
}
一个不太好的解决方案是为你的宏提出一个不太可能与其他包中使用的符号冲突的命名约定(例如,你可以将你的宏命名为EQ或EQ_(不要使用开头下划线,这是另一个问题)
相关文章:
- "error: no matching function for call to"构造函数错误
- 为什么类中的ostringstream类型的成员会导致";调用隐含删除复制构造函数";错误
- 尝试将unique_ptrs推送到向量时使用纯虚拟函数错误
- C++ OpenCV 卡尔曼滤波器构造函数错误
- C++:用户定义的显式类型转换函数错误
- C++ 合并字符串以'system'函数错误
- C++ wmain 函数错误时使用 Unicode
- 结构数组的构造函数错误,错误消息:没有构造函数实例与参数列表匹配
- C++ 中常量属性的初始化构造函数错误
- 线程 std::调用未知类型,无法专门化函数错误
- 表单显示对话框函数错误,并且不执行下面的语句
- 函数错误 C2059:语法错误:'>'不起作用
- STL向量上出现奇怪的复制构造函数错误
- C++ Visual Studio 重载函数错误:没有重载函数的实例与指定的类型匹配
- C++引用已删除函数错误
- 为什么通过带有文字编号的引用调用会出现"无匹配函数"错误?
- C++ 乘法定义的构造函数错误消息似乎错误
- 在 c++ 代码中将数组传递给函数错误
- FFMPEG avcodec_decode_video2函数错误代码
- 为什么我会收到转换函数错误