【发布时间】:2017-02-27 17:58:03
【问题描述】:
我遇到了一个我无法理解的编译时错误。我尝试在我的代码中使用boost::optional,一旦我包含boost/optional.hpp,我就无法再构建我的项目了。如果我将此包含声明注释掉,它会起作用。我的代码中还没有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;
};
}
编译器报错的地方在Boost头boost/utility/compare_pointees.hpp第36行。可以在GitHubhttps://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 ==========
这肯定不是 Boost 库的问题。但是我如何才能弄清楚我的课程或项目设置有什么问题?
附:即使我在项目中使用这些最原始的头文件和源文件,我也可以重现该行为:
头文件Test.h:
#pragma once
#include <boost/optional.hpp>
源文件Test.cpp:
#include "../include/Test.h"
【问题讨论】:
-
请将您的问题edit发送至minimal reproducible example 或SSCCE (Short, Self Contained, Correct Example)。同时发布文本,而不是图片。
-
向我们显示触发错误的确切行,并请编辑您的问题以将代码包含为文本,而不是屏幕截图。此外,
std::binary_function已被弃用。 -
除了“停止发布图片,我不能将它们复制/粘贴到repro”之外,关于“所以我的Boost发行版应该没有问题。”:就像可能,指定您使用的 boost 版本不会有什么坏处。
-
@SingerOfTheFall 这个弃用的用法来自 Boost 标头,而不是来自我的代码。
-
您是否有可能使用
/std:c++latest?我知道这个开关删除了一些将在 c++17 中删除的东西,并且 Boost(或这个特定的 Boost 库)可能还没有适应这种变化。如果您正在使用它,您应该尝试/std:c++14看看它是否适合您。
标签: c++ boost visual-studio-2015 optional boost-optional