0
所以我被困在一個討厭的問題,並花了一個小時已經在調查。C++錯誤:'內聯'只能出現在功能上
我有一個相當老的C++ - ish代碼的項目,我需要向它添加一些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
這裏有什麼問題,它可以修復嗎?
['std :: char_traits :: eq'](http: //en.cppreference.com/w/cpp/string/char_traits/cmp),宏一直是錯的 – MSalters
出於興趣你爲什麼要定義這些宏,以及爲什麼宏? –
正如我所說的,我必須處理遺留代碼。簡而言之:非常複雜的代碼,但是從數學的角度來看,代碼已經過很好的測試,從軟件角度來看,代碼非常笨爲了讓遺留代碼正常工作,我實際上重新整理了整個項目 - 重構的嘗試造成了太多的頭痛。 – benjist