哪个 C++ 语言功能在函数调用后重复括号?
Which C++ language feature is repeating parentheses after function call?
我正在使用 boost::program_options 库,下面的代码用于创建选项描述并向其添加选项:
po::options_description opts("SendFile Options");
opts.add_options()("help,h", "Print this help message")
("other,o","This is the other");
我的问题是,哪个C++语言特性允许您在调用add_options函数后直接以括号中包含的重复值的形式添加单独的描述?这叫什么,我将如何创建以这种方式工作的函数?
简化示例:
#include <string>
#include <vector>
#include <iostream>
class Options {
public:
Options& operator()(std::string text)
{
strings.push_back(text);
return *this;
}
std::vector<std::string> strings;
};
int main()
{
Options options{};
options("Some text")
("more text")
("even more text");
for(const auto& text : options.strings)
std::cout << text << '\n';
}
生产:
Some text
more text
even more text
我正在使用 boost::program_options 库,下面的代码用于创建选项描述并向其添加选项:
po::options_description opts("SendFile Options");
opts.add_options()("help,h", "Print this help message")
("other,o","This is the other");
我的问题是,哪个C++语言特性允许您在调用add_options函数后直接以括号中包含的重复值的形式添加单独的描述?这叫什么,我将如何创建以这种方式工作的函数?
简化示例:
#include <string>
#include <vector>
#include <iostream>
class Options {
public:
Options& operator()(std::string text)
{
strings.push_back(text);
return *this;
}
std::vector<std::string> strings;
};
int main()
{
Options options{};
options("Some text")
("more text")
("even more text");
for(const auto& text : options.strings)
std::cout << text << '\n';
}
生产:
Some text
more text
even more text