Viv*_*vit 3 c++ boost boost-optional visual-studio-2015 option-type
我遇到了一个我无法理解的编译时错误。我尝试在我的代码中使用boost::optional,一旦包含,boost/optional.hpp我就无法再构建我的项目。如果我注释掉这个 include 语句,它就会起作用。我什至在我的代码中还没有任何实际用法boost::optional,只是类标头中的 include 语句(请参阅下面的完整标头)。编译器错误C2143 syntax error: missing ',' before '<'发生在另一个 Boost 标头中boost/utility/compare_pointees.hpp(请参阅下面的 GitHub 链接)。我还成功地使用了 Boost 中的其他东西,就像boost::filesystem::path在同一个项目中一样,所以我的 Boost 发行版应该没有问题。
这是我的环境:Microsoft Visual Studio Professional 2015 Version 14.0.25431.01 Update 3和boost 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 request) = 0;
};
}
Run Code Online (Sandbox Code Playgroud)
报告编译器错误的位置位于 Boost header 中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): 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 ==========
Run Code Online (Sandbox Code Playgroud)
这肯定不是Boost库的问题。但我怎样才能找出我的课程或项目设置有什么问题呢?
PS 即使我在项目中使用这些最原始的头文件和源文件,我也可以重现该行为:
头文件Test.h:
#pragma once
#include <boost/optional.hpp>
Run Code Online (Sandbox Code Playgroud)
源文件Test.cpp:
#include "../include/Test.h"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3586 次 |
| 最近记录: |