C++指针上的关键字运算符"this"

C++ keyword operator on "this" pointer

本文关键字:运算符 this 关键字 指针 C++      更新时间:2023-10-16

努力理解我在开源代码中遇到的这种语法:

/// cast *this into an gpstk::RinexNavData.
/// @throw if the record is invalid or not an ephemeris (isNav()==false)
operator RinexNavData() throw(gpstk::Exception);
/// cast *this into a gpstk::RinexObsData
/// @throw if the record is invalid or not an observation (isObs()==false)
operator RinexObsData() throw(gpstk::Exception);

如果我正确解释评论,它正在通过"此"指针更改对象的类型。但这似乎是通过操作员完成的吗?无法打入涉及关键字" this"的良好网络搜索。寻找有关"操作员"的使用方式的参考或解释。C 操作员的Web搜索不会导致我发现到目前为止的任何东西。

不要在此处思考this的使用;*this只是表示"当前对象",因此程序员正在使用速记来描述操作员的作用。

的确,像任何转换操作员一样,它采用当前对象,并为 convert 提供一种手段。