Learning OOP - Setting up child class contructor when base class constructor accepts paratmeters
When there is no implicit constructor in the class you extend, you must explicitly call it:
myEMA(int period, int shift):myMovingAverage(period, shift) { this.maMethod = MODE_EMA; }
- You must construct the base class in a initialization list. Structures and Classes - MQL4 Documentation
myEMA::myEMA(int period, int shift) : myMovingAverage(period, shift){}
this.maPeriod = period;You don't need the "this."this.maMethod = MODE_EMA;
maMethod is a private variable, will not compile.
Thanks guys, the compiler went through with no errors.
Nice to see you're still kicking around WHRoeder, you were helping me with coding issues in like 2010.
Does it matter if I use the "this." operator in the code? It just helps me personally read the code better from an OOP point of view.
I guess the correct question would be, would there be any negative effect of using the this statement?
Hey everyone, learning to uses classes to neaten up my coding and get with the times.
I am doing a basic moving average class set. I have created the base moving average class - which seems to work ok. Now I am trying to make an exponential moving average extended class, but having a bit of trouble with the syntax...
Now when I try to set up the child class I get a compile error...
I am guessing it is because the base class takes parameters in the constructor. I also tried...
I am still getting a wrong parameters count error for the constructor. Please help set me straight.