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?
The ampersand is part of the type in the declaration and signifies that the type is a reference. Reference is a form of indirection, similar to a pointer.
Introduction to Operator Overloading It's a type of polymorphism in which an operator is overloaded to give it the user-defined meaning. C++ allows us to specify more than one definition for a function name or an operator in the same scope, which is called function overloading and operator overloading, respectively.
As i++ does automatic typecasting and uses a compiler instruction which internally uses iadd instruction, i=i+1 is faster than i++.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With