Object in parameter specification

杀马特。学长 韩版系。学妹 提交于 2019-12-23 22:36:40

问题


Why this sentence is valid in C++?

qi::rule<Iterator, std::string(), skipper<Iterator> > name;

Extracted from here:

  • Boost::spirit::qi - mini C compiler tutorial - function.hpp

The definition of rule is (resumed) the following:

template <typename Iterator, typename T1, typename T2,
                             typename T3, typename T4>
struct rule : boost::proto::extends<bla, bla>, parser<bla, bla>
{
  bla, bla
};

Extracted from here:

  • rule.hpp file

The rule definition expects a type, however I send it an object. It is possible?


回答1:


In this context, std::string() means the type of something that returns an std::string and has no parameters. For example,

std::string foo() { return "Foo!\n"; }

or an instance of

struct Foo
{
  std::string operator()() const { return "Foo!\n"; }
};



回答2:


You don't give it an object. std::string() is the type of a function that takes no arguments and returns an std::string.



来源:https://stackoverflow.com/questions/13472591/object-in-parameter-specification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!