I have a strange problem with overloading the -> and * operators. I'm trying to do this to make dereferencing a pointer to the class intrinsically safe. I think the problem is the same in both cases, so I'll describe the * operator:
and in myreal.cpp
const CMyReal& operator * (void);
where CMyReal::Bad is a static object representing Not-A-Number.
const CMyReal& CMyReal::operator * (void)
Now, when I write:
it calls my overloaded operator function and I get Not-A-Number, as expected.
CMyReal *myreal = NULL;
float x = (myreal->operator *()).value();
But if I write
it doesn't call the overloaded operator function but tries to dereference the NULL pointer directly and I get an access violation error.
float x = (*myreal).value();
Similarly, (myreal->operator ->())->value() is ok, but myreal->value() fails with an access violation.
Any idea what I am doing wrong?