Ran into this at work "operator ClassName *". What does this mean?

c++

Solution

This is an overload of the conversion operator. Whenever a `ClassRef` object needs to be converted to a `ClassName` pointer type, this operator is called.

So;

ClassRef r;
ClassName * p = r;

will make use of this overload.

Problem

The class with this code is a reference class for a pointer of ClassName, i.e.: ``` class ClassName; class ClassRef { ClassName* m_class; ... operator ClassName *() const { return m_class; } ... ``` I am assuming this is used for pointer validity checks, such as: ``` ClassRef ref(new ClassName()) if (ref) { bla bla bla } ``` Am I correct in my thinking?

Original source