简体   繁体   中英

C++ keyword operator on “this” pointer

Struggling to understand this syntax that I've run across in open source code:

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

If I interpret the comment correctly, it is changing the type of the object via the "this" pointer. But this appears to be done via an operator? Can't hit on a good web search that involves the keyword "this". Looking for a reference or explanation on how this use of "operator" works. Web search of C++ operator doesn't lead to anything like this, that I've found so far.

Don't overthink the use of this here; *this just means "the current object", so the programmer is using a shorthand to describe what the operator does.

Indeed, like any conversion operator , it takes the current object and provides a means to convert it to a different type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM