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:
Unfortunately, your override of operator * in your CMyReal class only affects the use of a * when you have an object of type CMyReal. You are trying to use it on a pointer to a CMyReal, which is not the same type.
As soon as you introduce a raw pointer, you aren't going to be able to override the operator * and get a dereference of the raw pointer to call your overridden routine.
I don't know if this is at all useful to you, but you could wrap the pointer inside of a class - something like:
Thanks very much for your replies. I think I understand it now. I guess this is very closely related to the 'smart pointer' templates that are available for C++. I had this idea that by simply overriding an operator, I could make my class intriniscally safe without requiring the caller to change the way it called the class and with no additional overhead. I'm really a C programmer...
I suppose the real surprise here is that the ->operator * () version worked at all. Come to think of it,
when myreal is NULL looks decidedly dodgy
Anyway, thanks for your time.
Last edited by iangoldby; March 4th, 2004 at 03:35 AM.