This is an example from mql5 documentation. Here is the link to that page. And below is this code.
//+------------------------------------------------------------------+//| Класс с конструктором по умолчанию |//+------------------------------------------------------------------+class CFoo
{
datetime m_call_time; // время последнего обращения к объектуpublic:
//--- конструктор с параметром, имеющем значение по умолчанию, не является конструктором по умолчанию
CFoo(constdatetime t=0){m_call_time=t;};
//--- конструктор копирования
CFoo(const CFoo &foo){m_call_time=foo.m_call_time;};
string ToString(){return(TimeToString(m_call_time,TIME_DATE|TIME_SECONDS));};
};
//+------------------------------------------------------------------+//| Script program start function |//+------------------------------------------------------------------+voidOnStart()
{
// CFoo foo; // такой вариант использовать нельзя - конструктор по умолчанию не задан//--- допустимые варианты создания объекта CFoo
CFoo foo1(TimeCurrent()); // явный вызов параметрического конструктора
CFoo foo2(); // явный вызов параметрического конструктора с параметром по умолчанию
CFoo foo3=D'2009.09.09'; // неявный вызов параметрического конструктора
CFoo foo40(foo1); // явный вызов конструктора копирования
CFoo foo41=foo1; // неявный вызов конструктора копирования
CFoo foo5; // явный вызов конструктора по умолчанию (если конструктор по умолчанию отсутствует,// то вызывается параметрический конструктор с параметром по умолчанию)//--- допустимые варианты получения указателей CFoo
CFoo *pfoo6=new CFoo(); // динамическое создание объекта и получение указателя на него
CFoo *pfoo7=new CFoo(TimeCurrent());// ещё один вариант динамического создания объекта
CFoo *pfoo8=GetPointer(foo1); // теперь pfoo8 указывает на объект foo1
CFoo *pfoo9=pfoo7; // pfoo9 и pfoo7 указывают на один и тот же объект// CFoo foo_array[3]; // такой вариант использовать нельзя - конструктор по умолчанию не задан//--- выведем значения m_call_timePrint("foo1.m_call_time=",foo1.ToString());
Print("foo2.m_call_time=",foo2.ToString());
Print("foo3.m_call_time=",foo3.ToString());
Print("foo4.m_call_time=",foo4.ToString());
Print("foo5.m_call_time=",foo5.ToString());
Print("pfoo6.m_call_time=",pfoo6.ToString());
Print("pfoo7.m_call_time=",pfoo7.ToString());
Print("pfoo8.m_call_time=",pfoo8.ToString());
Print("pfoo9.m_call_time=",pfoo9.ToString());
//--- удалим динамически созданные объектыdelete pfoo6;
delete pfoo7;
//delete pfoo8; // удалять pfoo8 явно не нужно, так как он указывает на автоматически созданный объект foo1//delete pfoo9; // удалять pfoo9 явно не нужно, так как он указывает на тот же объект, что и pfoo7
}
On what basis was the conversion of non-constant objects to constant objects abolished? I have hundreds of internal methods that stop working, just because they're not constant, and the visiels can't be used in constant objects now. Hundreds of my functions are tied to constant CObject.Compare(...) and now they all don't work!
If "A" contains a non-constant method, but is itself passed to the function as a constant object, it is now impossible to call this non-constant method in the function.
class A
{
public:
void PrintMyName(){printf("my name A");}
};
void f(const A* a)
{
a.PrintMyName(); //Хренушки. Теперь PrintMyName должен быть константым.
}
voidOnStart()
{
A a; //не const A
f(GetPointer(a));
}
And now attention question: let's wipe the CObject.Compare():
virtualint Compare(
CObject const * node, // элемент int mode=0// вариант
) const
O.k. it's a constant method that takes a constant object node. It's his right to declare node as constant. But on what basis should Compare now only work with constant methods of node? Node is not obliged to have constant methods for the sake of Compare. But it turns out that just on the grounds that the object is complex and has no constant methods, now he can not use the standard library with all that it implies!!!
If "A" contains a non-constant method, but is itself passed to the function as a constant object, then this non-constant method cannot now be called in the function.
That's right, that's how it should be, otherwise what's the point of specifying
If "A" contains a non-constant method, but is itself passed to the function as a constant object, then this non-constant method cannot now be called in the function.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Please post all your code.
This is an example from mql5 documentation. Here's a link to that page. And below is this code.
It seems that with the update, not only the mandatoryplacement of static class data members was introduced,
but also removed the implicit call to the parametric constructor.
Use an explicit call:
On what grounds have they cancelled conversion of non-constant objects to constant ones?
Everything compiles normally - no errors or warnings
If there are any errors, it is only in struct, but they will get to them eventuallyEverything compiles without errors or warnings
If "A" contains a non-constant method, but is itself passed to the function as a constant object, it is now impossible to call this non-constant method in the function.
And now attention question: let's wipe the CObject.Compare():
O.k. it's a constant method that takes a constant object node. It's his right to declare node as constant. But on what basis should Compare now only work with constant methods of node? Node is not obliged to have constant methods for the sake of Compare. But it turns out that just on the grounds that the object is complex and has no constant methods, now he can not use the standard library with all that it implies!!!It is now mandatory to place static members.
And how are you supposed to place complex static objects if static constructors are not allowed?
If "A" contains a non-constant method, but is itself passed to the function as a constant object, then this non-constant method cannot now be called in the function.
That's right, that's how it should be, otherwise what's the point of specifying
instead of
void f(A* a)If "A" contains a non-constant method, but is itself passed to the function as a constant object, then this non-constant method cannot now be called in the function.
And how are you supposed to place complex static objects if static constructors are not allowed?