gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-27 23:47:59 25 4
gpt4 key购买 nike

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

/// 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”指针更改对象的类型。但这似乎是通过运算符(operator)完成的?无法找到涉及关键字“this”的良好网络搜索。寻找有关“运算符”的使用方式的引用或解释。到目前为止,我在网上搜索 C++ 运算符并没有找到类似这样的结果。

最佳答案

不要想太多在这里使用this*this 仅表示“当前对象”,因此程序员使用简写来描述运算符的作用。

确实,像任何conversion operator ,它获取当前对象并提供一种将其转换为不同类型的方法。

关于 "this"指针上的 C++ 关键字运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49015140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com