c++ - Boost.Spirit 编译器无法识别 std::pair

标签 c++ boost compiler-errors boost-spirit

#include <iostream>
#include <boost/spirit/include/qi.hpp>

namespace qi = boost::spirit::qi;
int main ()
{
    // the following parses "1.0 2.0" into a pair of double
    std::string input("1.0 2.0");
    std::string::iterator strbegin = input.begin();
    std::pair<double, double> p;
    qi::phrase_parse(strbegin, input.end(),
            qi::double_ >> qi::double_,       // parser grammar 
            qi::space,                        // delimiter grammar
            p);                               // attribute to fill while parsing
}

这是 boost 文档中的示例 http://www.boost.org/doc/libs/1_55_0/libs/spirit/doc/html/spirit/abstracts/attributes/compound_attributes.html

编译错误

main.cpp:14:14:   instantiated from here
/usr/local/include/boost/spirit/home/qi/detail/assign_to.hpp:152:13: error: no matching function for call to ‘std::pair<double, double>::pair(const double&)’
/usr/local/include/boost/spirit/home/qi/detail/assign_to.hpp:152:13: note: candidates are:
/usr/include/c++/4.6/bits/stl_pair.h:108:21: note: template<class _U1, class _U2> std::pair::pair(const std::pair<_U1, _U2>&)
/usr/include/c++/4.6/bits/stl_pair.h:103:26: note: std::pair<_T1, _T2>::pair(const _T1&, const _T2&) [with _T1 = double, _T2 = double]
/usr/include/c++/4.6/bits/stl_pair.h:103:26: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/4.6/bits/stl_pair.h:99:26: note: std::pair<_T1, _T2>::pair() [with _T1 = double, _T2 = double]
/usr/include/c++/4.6/bits/stl_pair.h:99:26: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/4.6/bits/stl_pair.h:87:12: note: std::pair<double, double>::pair(const std::pair<double, double>&)
/usr/include/c++/4.6/bits/stl_pair.h:87:12: note:   no known conversion for argument 1 from ‘const double’ to ‘const std::pair<double, double>&’
make: *** [all] Error 1

最佳答案

您需要使该对适应 fusion 序列,这是通过包含

#include <boost/fusion/adapted/std_pair.hpp>

关于c++ - Boost.Spirit 编译器无法识别 std::pair,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21957810/

相关文章:

c++ - 如何表示指向地址空间开头的指针?

c++ - 二进制搜索数学函数

c++ - 查找耗时

c++ - 如何使用 Boost.Graph 从特定节点遍历图分支?

c++ - 解析 JSON 文件 (C++ Boost)

c - 如何修复C中的 “Expression is not a function locator”错误?

C++ static_cast 与 dynamic_cast

c++ - std::pair 提示类型不完整

linux - srlua makefile 错误 lua.h No such file or directory

java - 无法编译for循环