【问题标题】:Boost.Program_options syntaxBoost.Program_options 语法
【发布时间】:2010-10-30 05:28:10
【问题描述】:

我目前正在阅读 Boost.Program_options 教程。

这是他们介绍的一些代码:

// Declare the supported options.
po::options_description desc("Allowed options");
desc.add_options()
    ("help", "produce help message")
    ("compression", po::value<int>(), "set compression level")
;

我理解这段代码背后的目的,但是语法让我感到困惑。缩进线是函数的参数吗?括号是什么?

【问题讨论】:

    标签: c++ boost


    【解决方案1】:

    我想desc.get_options() 返回一个定义operator() 的类的对象,而operator() 又返回相同的对象。因此,缩进的行是对该运算符的调用,括号中带有参数。

    查看boost/program_options/options_description.hpp,您可以看到有问题的类是options_description_easy_init,它确实有几个operator(),例如:

        options_description_easy_init&
        operator()(const char* name,
                   const char* description);
    

    【讨论】:

    • 这通常被称为函子。
    • @Sam Miller:对,一个仿函数或一个函数对象。
    猜你喜欢
    • 1970-01-01
    • 2013-03-22
    • 2013-07-14
    • 2011-08-22
    • 1970-01-01
    • 2016-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多