我正在为一个类创建一个类图,该类在其头文件中有许多与此类似的定义.
1 2 3 4 5
const std::pair<Controller<_Tp,_Val>*, _Val>& getHighestBidder(_Tp obj) const;
Run Code Online (Sandbox Code Playgroud)
我知道他们中的几个人做了什么,
2) says that this method will return a std::pair<Controller<_Tp, _Val>*, _Val>
3) gives the name of the function
4) defines the type of object this function accepts as a parameter
Run Code Online (Sandbox Code Playgroud)
但是,1和5是什么意思?
任何帮助/指针都会很棒.谢谢
首先,请注意它不返回a std::pair<Controller<_Tp, _Val>*, _Val>,它返回a std::pair<Controller<_Tp, _Val>*, _Val> &,即对已存在的此类对象的引用.
(1)表示它const是对象的引用; 你不能通过这个引用修改对象.
(5)表示这是一个const成员函数,即它不会修改它被调用的对象.