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

时间:2018-02-27 18:02:11

标签: c++ this operator-keyword

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

/// 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);

如果我正确地解释了注释,它正在通过"这个"来改变对象的类型。指针。但这似乎是通过运营商完成的?无法进行涉及关键字"此"的良好网络搜索。寻找关于如何使用"运算符"的参考或解释。作品。对C ++运算符的网络搜索并没有导致到目前为止我发现的类似内容。

1 个答案:

答案 0 :(得分:3)

不要在这里过度使用this; *this只意味着"当前对象",所以程序员使用简写来描述操作员的行为。

实际上,与任何conversion operator一样,它会获取当前对象,并提供转换为其他类型的方法。