问题
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