I stumbled upon this "problem" earlier today.
I have this class and it contains a conversion operator. Something like:
class myClass {
public:
...
operator anotherClass*() { return anotherClassPtr; }
...
}
Now this all works well .. until I made this silly mistake:
void yetAnotherClass::foo(myClass* _p_class)
{
...
anotherClass* lp_anotherClass = (anotherClass*)_p_class;
...
}
And it took me a long time to figure out why the lp_AnotherClass ptr was set to something non-zero whilst I was sure that the anotherClassPtr in _p_class was 0.
Is there anything I could have added to myClass that would have prevented me from making this mistake? (i.e. the compiler would have spat out some error) Is it possible to prevent an object ptr being cast to something else?