
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
The new operator creates an instance of the class and a constructor is called in conjunction with it. It is written in the syntax, so there is no other way to call it.
I proceeded from this example:
Roughly speaking, there are no parentheses (constructor call) here. It's possible that I'm still missing something.This code is almost no different from multiple inheritance.
In fact, class C_C has access to data of C_A and C_B through appropriate pointers.I was based on this example:
Here, roughly speaking, there are no parentheses (constructor calls). It's possible that I don't understand something yet.Why me, it's not for me, it's for the central laundry, I didn't use brackets :o)
My compiler doesn't complain about missing parentheses...
Anyway, a question suddenly arose: what is the right way to do it? Or it makes no difference whether there are brackets or not?
My compiler doesn't complain about missing parentheses...
Anyway, a question suddenly arose: what's the right way? Or it makes no difference if there are brackets or not?
If it works both ways, it's rather a matter of syntax unification. The main thing is that it doesn't affect speed.
ZS And does it work at all? To be honest I have not checked, I always write with parentheses.
If it works both ways, it's more a matter of syntax unification. The main thing is not to affect the speed.
ZS Does it work at all? To be honest I haven't checked, I always write with brackets.
I haven't read the description of creating class objects dynamically in MQL5, but in C++ you can do it without brackets (standard constructor is called) and with brackets (constructor is called depending on parameters in brackets). Example:
class CExample
{
int param;
public:
CExample();
CExample(int x);
~CExample();
}
CExample::CExample(int x)
{
param = x;
}
//..........вызов..............
//..где-то в тексте программы..
CExample *ex1 = new CExample; //создание с конструктором CExample();
CExample *ex1 = new CExample(); //создание с конструктором CExample();
CExample *ex1 = new CExample(value); //создание с конструктором CExample(int x);
In mql5 no parameters can be passed to the constructor yet.
I haven't read the description of creating class objects dynamically in MQL5, but in C++ you can do it without brackets (standard constructor is called) and with brackets (constructor is called depending on parameters in brackets). Example:
Got it, thanks for the simple and straightforward explanation. It turns out that parentheses are for possible parameters.
And the description of how to create dynamic class objects in MQL5 is very concise:
MQL5 Reference / Language Basics / Operators / Object creation operator new
MQL5 Reference / Language Basics / Data Types / Object Pointers