包括boost / optional.hpp时的C2143语法错误 [英] C2143 syntax error when including boost/optional.hpp
问题描述
我遇到了一个我无法理解的编译时错误。我尝试在我的代码中使用 boost :: optional
,并且一旦我包括 boost / optional.hpp
I不能再建立我的项目了。如果我评论这个包括语句出来,它的工作原理。我甚至没有任何实际使用 boost :: optional
在我的代码中,只是类头中的include语句(见下面的完整标题)。编译器错误是 C2143语法错误:在另一个Boost头中发生的<'
之前缺少','before boost / utility / compare_pointees.hpp
(参见下面的GitHub链接)。我也成功地使用了其他的东西从Boost像 boost :: filesystem :: path
在同一个项目已经,所以应该没有问题,我的Boost分布。 p>
这里是我的环境: Microsoft Visual Studio Professional 2015版本14.0.25431.01更新3
和 1.62.0
。我还使用第三方库 C ++ REST SDK ,一切都是C ++标准库的东西。
我的标题看起来像这样。我想用 boost :: optional< size_t>
作为返回类型添加一个新方法。
#pragma once
#include< boost / optional.hpp> //< ==== ERROR
// C ++ REST SDK
#define _TURN_OFF_PLATFORM_STRING
#include< cpprest / http_listener.h>
#include< cpprest / http_msg.h>
namespace SANDBOX :: REST
{
class HttpGetHandler
{
public:
virtual void HandleHttpGetRequest(web :: http :: http_request请求)= 0;
};
}
报告编译器错误的位置在Boost标头 boost / utility / compare_pointees.hpp
,第36行。您可以在GitHub上的 https://github.com/boostorg/utility/blob/boost-1.62.0/include/boost/ utility / compare_pointees.hpp
编译器输出只显示以下消息:
1> D:\dev\lib\boost_1_62_0\boost / utility / compare_pointees.hpp(36):错误C2143:语法错误:在'<'$之前缺少',' b $ b 1> D:\dev\lib\boost_1_62_0\boost/ utility / compare_pointees.hpp(40):note:参考类模板实例化'boost :: equal_pointees_t< OptionalPointee>'正在编译
1> D :\dev\lib\boost_1_62_0\boost/ utility / compare_pointees.hpp(59):错误C2143:语法错误:缺少','之前'<'
1> D:\dev\lib\boost_1_62_0\boost/ utility / compare_pointees.hpp(63):note:参考类模板实例化'boost :: less_pointees_t< OptionalPointee>'正在编译
=== ======= Build:0 succeeded,1 failed,2 up-to-date,0 skipped ==========
这肯定不是Boost库的问题。但我怎么知道,我的课程或项目设置有什么问题?
即使我在我的项目中使用这些最原始的头文件和源文件,我也可以重现这种行为:
头文件 Test.h
:
#pragma once
#include< boost / optional.hpp>
源文件 Test.cpp
:
#include../include/Test.h
我可以找出原因,因为一个有价值的提示 jv_ 。我打开编译器开关 / std:c ++ latest
在我的项目设置中能够使用C ++ 17 嵌套命名空间定义功能。激活此开关将删除一些已弃用的语言功能,特别是 std :: binary_function
,它仍然在当前Boost分发(1.62.0)中使用,因此产生编译器错误。最后,我决定删除开关 / std:c ++ latest
(并使用普通方式声明我的命名空间),这解决了问题。谢谢大家帮助我。
I'm stuck with a compile-time error which I cannot understand. I try to use boost::optional
in my code, and as soon as I include boost/optional.hpp
I cannot build my project any longer. If I comment this include statement out, it works. I don't even have any actual usage of boost::optional
in my code yet, just the include statement in the class header (see full header below). The compiler error is C2143 syntax error: missing ',' before '<'
which happens in another Boost header boost/utility/compare_pointees.hpp
(see GitHub link below). I also successfully use other stuff from Boost like boost::filesystem::path
in the same project already, so there should be no problem with my Boost distribution as such.
Here is my environment: Microsoft Visual Studio Professional 2015 Version 14.0.25431.01 Update 3
and boost 1.62.0
. I also use the third-party library C++ REST SDK, everything else is C++ standard library stuff.
My header looks like this. I want to add a new method with boost::optional<size_t>
as return type.
#pragma once
#include <boost/optional.hpp> // <==== ERROR
// C++ REST SDK
#define _TURN_OFF_PLATFORM_STRING
#include <cpprest/http_listener.h>
#include <cpprest/http_msg.h>
namespace SANDBOX::REST
{
class HttpGetHandler
{
public:
virtual void HandleHttpGetRequest(web::http::http_request request) = 0;
};
}
The place, where the compiler error is reported, is in the Boost header boost/utility/compare_pointees.hpp
, line 36. You can view the full content of this file on GitHub under https://github.com/boostorg/utility/blob/boost-1.62.0/include/boost/utility/compare_pointees.hpp
The compiler output shows nothing more than these messages:
1>D:\dev\lib\boost_1_62_0\boost/utility/compare_pointees.hpp(36): error C2143: syntax error: missing ',' before '<'
1> D:\dev\lib\boost_1_62_0\boost/utility/compare_pointees.hpp(40): note: see reference to class template instantiation 'boost::equal_pointees_t<OptionalPointee>' being compiled
1>D:\dev\lib\boost_1_62_0\boost/utility/compare_pointees.hpp(59): error C2143: syntax error: missing ',' before '<'
1> D:\dev\lib\boost_1_62_0\boost/utility/compare_pointees.hpp(63): note: see reference to class template instantiation 'boost::less_pointees_t<OptionalPointee>' being compiled
========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========
It's surely not a problem of the Boost library. But how can I figure out, what's wrong with my classes or project settings?
P.S. I can reproduce the behavior even if I use these most primitive header and source file in my project:
Header file Test.h
:
#pragma once
#include <boost/optional.hpp>
Source file Test.cpp
:
#include "../include/Test.h"
I could figure out the reason due to a valuable hint by jv_. I turned on compiler switch /std:c++latest
in my project settings to be able to use C++17 nested namespace definition feature. Activating this switch removes some deprecated language features, in particular std::binary_function
, which is still in use in the current Boost distribution (1.62.0), hence producing the compiler error. Finally, I decided to remove the switch /std:c++latest
(and use the ordinary way to declare my namespaces) and this solved the issue. Thank you all for helping me.
这篇关于包括boost / optional.hpp时的C2143语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!