返回的内容以及本文档描述的功能中所采取的措施

What is being returned and what is being taken in the function described by this documentation?

本文关键字:功能 文档 返回 描述      更新时间:2023-10-16

我正在从http://www.boost.org/doc/libs/1_54_0/doc/doc/html/boost/boost/boost/program_options/variables_map.map.html

const variable_value & operator[](const std::string & name) const;

我正在考虑评估C 项目的逻辑。您无法从C 中的函数返回数组,因此我对在参数列表之前的方括号感到困惑。我也对为什么在尾随列表之后有一个const感到困惑。

尾随const表示函数中的"此"参数也为const。这意味着在此函数中不能突变类状态,并且该函数不能调用其他非const成员函数。

功能签名本身使[]运算符超载。该函数的返回类型为" const variable_value&"。超载[]运算符使您可以按照您想要的任何形式索引您的课程。通常,[]用于访问元素(arr [1] ==数组的第二个元素)。使用此过载,可以用字符串参数(ThatClass [" Somestring"])索引类。