You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
My first reply.
I never use "!ptr" because I don't know what it does. Never trust the documentation 😉
I either is ptr==NULL if I am sure !NULL is valid, or the full if version as shown in the topic.
You probably misunderstood me. I meant, "What OOP patterns make you need to check pointers?"
I find the question strange. An OOP pattern is not about implementation details, so not about using pointers or not, so not about checking them or not.
Unless I missed something ?
Yes, thus I need to check beforehand to avoid null pointer exceptions. That's what this topic is about. The only crux of this whole topic is:
Using !(pointerObj) handles both NULL and INVALID pointers.
If you look at many places in the MQL5 source code, you'll see that only (objectPtr != null) is checked to avoid NPEs.. So I was'not entirely sure why it's not checked with !I(pointerObj).
I either is ptr==NULL if I am sure !NULL is valid, or the full if version as shown in the topic.
I think CheckPointer() is better:
I find the question strange. An OOP pattern is not about implementation details, so not about using pointers or not, so not about checking them or not.
Unless I missed something ?
Using !(pointerObj) handles both NULL and INVALID pointers.
You're wrong, here's the proof. You still haven't listened to the best advice.
No, I'm wrong. I forgot that !pointer is an implicit call to CheckPointer(). But I would still prefer an explicit call.
You're wrong, here's the proof. You still haven't listened to the best advice.
No, I'm wrong. I forgot that !pointer is an implicit call to CheckPointer(). But I would still prefer an explicit call.
I think CheckPointer() is better:
I wasn't clear enough previously.
Either I know the pointer can only be valid or NULL. Then I will just use : if(ptr!=NULL) ...
But sometimes the pointer can be different of NULL and be invalid (as you have showed), then I will use the "full"
I don't like to use because it's unclear and I don't know what is really done (I don't trust the documentation).
I wasn't clear enough previously.
Either I know the pointer can only be valid or NULL. Then I will just use : if(ptr!=NULL) ...
But sometimes the pointer can be different of NULL and be invalid (as you have showed), then I will use the "full"
I don't like to use because it's unclear and I don't know what is really done (I don't trust the documentation).
Yes, I think so too. That's the only clear and direct answer on the entire topic. Thanks.