Questions on OOP in MQL5 - page 41

 
Igor Makanu:

looked at the results of my battle with OOP-style code - hmmm... excellent! ))))


I have a question, but in my code, well, three times exactly, I use a construction like:

calls all in privat methods, but is there a "Jedi method ?" to get away in the source code from CheckPointer(m_order)==POINTER_INVALID

I am asking about some get / set

no special problems, but so to speak a whim, or while the thirst for knowledge of OOP methods in C++ has not yet abated

If the question is "many letters", then !CheckPointer(mPtr), and if the function call, you initialize all pointers to NULL in the constructor and compare to it in the code, not forgetting when deleting ptr; ptr=NULL;

 
Igor Makanu:

looked at the results of my battle with OOP-style code - hmmm... excellent! ))))


I have a question, but in my code, well, three times exactly, I use a construction like:

calls all in privat methods, but is there a "Jedi method ?" to get away in the source code from CheckPointer(m_order)==POINTER_INVALID

I am asking about some get / set

no special problems, but so to speak a whim, or while the thirst for knowledge of OOP methods in C++ has not yet abated


Igor, look at this example, I think that's what you're asking.

 
Vladimir Simakov:

If the question is "many letters", then !CheckPointer(mPtr), and if in a function call, you initialise all pointers to NULL in the constructor and compare to it in the code, not forgetting when deleting ptr; ptr=NULL;

Well and this, for sugar:

#define  DELETE(dObj) do if (dObj!=NULL) {delete dObj; dObj=NULL;} while(false)
 
Igor Makanu:

No special problems, but so to say a whim, or while the thirst for learning OOP methods in C++ hasn't died down yet.

I strongly recommend that you initialize all the fields of the class with default values in the constructor. The point is that if you want to do this:

void foo(){
   CClass someClass;
   someClass.DoSomething();
}

nobody will initialize the fields of your class and there will be rubbish values.

 
Vladimir Simakov:

And this, for sugar:

No, I've almost given up on definitions, I just don't want to wrap anything, as I wrote a couple of weeks ago - I want to see pure OOP-style code for now, evaluate flexibility and possibilities

HH: I just wrapped descendants in define at creation, not to write the same initialization on 3 lines, it's easier to add methods later, i.e. in the source code on one line so far

#define  CLASS(NAME,FUNC)....

CLASS(CStrategy01,ReOpenOrder(__FUNCTION__,getDealType()==BUY ? SELL : BUY));
Roman:


Igor, take a look at this example, I think that's what you're asking.

no, i mean the equivalent in c# - operator ?? ( null-join operator ), something similar in logic I want to see in C++ style


UPD:

Vladimir Simakov:

I highly recommend initialising all fields of a class with default values in the constructor. The point is that if you want to do this:

If you're asking for a macro, no one will initialise the fields of your class and there will be rubbish values.

that's what I did, constructor with initializing anything and everything in the base class, descendants initialize the base class:

that's exactly what I wrapped it in a macro, so I wouldn't forget to initialize properly ))))

#define CLASS(NAME,FUNC) class NAME : public CStrategy{\
public:\
   NAME(SStrategySettings &set):CStrategy(set){ }\
   virtual void NextStepStrategy(void) {FUNC;}}
//____________________________________________________________________
 
Igor Makanu:

No, I've almost given up on definitions, I just don't want to wrap anything, as I wrote a couple of weeks ago - I want to see pure OOP-style code for now, evaluate flexibility and possibilities

ZS: only wrapped descendants in define at creation, not to write the same initialization on 3 lines, it's easier to add methods later, i.e. in the source code on one line for now

no, i mean the equivalent in c# - operator ?? ( null-join operator ), I want to see something similar in logic in C++ style

The preprocessor is a waste of time. Along with templates, they are the strongest tools. There seems to be no analogue of the ?? operator. C++ is more hardcore in this respect.
 
Vladimir Simakov:
Your refusal of the preprocessor is in vain. Along with templates they are the most powerful tools. There seems to be no analogue of the ?? operator. C++ is more hardcore in this respect.

I am still in a battle for pure OOP style, I want to learn all the OOP techniques, while there is an asset on the forum ;)

I'm up to speed on the preprocessor, but ... I think I shouldn't abuse it, at least, not my style, I may screw up, and I certainly won't be able to read code with multiple macrosubstitutions, and how to look for bugs... well, it's easier to rewrite - so, not necessary yet


templates... Well, I don't like what the developers offer in SB, I've looked through them all, it's hard to say for what purpose they were included in SB, maybe their time has not come yet

about C++ templates porting to MQL - it's time, as discussion showed, that in most cases C++ templates require fine-tuning for MQL - it's easier to go back to .dll and not to bother MQL ))))

 
Igor Makanu:

I am still in a battle for pure OOP style, I want to learn all the OOP techniques, while there is an asset on the forum ;)

I'm up to speed on the preprocessor, but ... I think I shouldn't abuse it, at least, not my style, I may screw up, and I certainly won't be able to read code with multiple macrosubstitutions, and how to look for bugs... well, it's easier to rewrite - so, not necessary yet


templates... Well, I don't like what the developers offer in SB, I've looked through them all, it's hard to say for what purpose they were included in SB, maybe their time has not come yet

about C++ templates porting to MQL - it's time, as discussion showed, that in most cases C++ templates require fine-tuning for MQL - it's easier to go back to .dll and not to bother MQL ))))

You can write your own templates that way.))
 
Vladimir Simakov:
You can write templates that way yourself.)))

Yup ))))

I have finished reading the help and skipped override, thank goodness everything is in macros, edits, well, exactly in one copy-paste

#define CLASS(NAME,FUNC) class NAME : public CStrategy{\
public:\
   NAME(SStrategySettings &set):CStrategy(set){ }\
   void NextStepStrategy(void) override {FUNC;}}

UPD:

no it isn't, got out for permission control itself, no need for public method!

#define CLASS(NAME,FUNC) class NAME : public CStrategy{\
private:\
void NextStepStrategy(void) override {FUNC;}\
public:\
   NAME(SStrategySettings &set):CStrategy(set){ }}
 
Vladimir Simakov:

And then there's this, for sugar:

#define  DELETE(dObj) do if (dObj!=NULL) {delete dObj; dObj=NULL;} while(false)

I wanted to write what I used to have instead of

if( CheckPointer(m_order)==POINTER_INVALID )

it was like this:

if(m_order==NULL)

but remembered how to check macro substitutions in MQL

void OnStart()
{  int a = 0;
#ifdef NULL
   a = 1;
#endif

   Print("a = ",a);
   Print("POINTER_INVALID = ",POINTER_INVALID);
   Print("NULL = ",(int)NULL);   // без (int) не компилируется!!!

}

2019.09.16 22:57:42.837 tst (EURUSD,H1) a = 1

2019.09.16 22:57:42.837 tst (EURUSD,H1) POINTER_INVALID = 0

2019.09.16 22:57:42.837 tst (EURUSD,H1) NULL = 0


and if memory serves me correctly, at the beginning of the year it was possible to unprinter NULL into the log and get 0 there , now an error appears

I.e. the behavior NULL as if should not change in the future, but what is substituted there instead of NULL is not clear, probably if this situation is checked now, as writtenif(CheckPointer(m_order)==POINTER_INVALID)) ) it is so to say the correct code))