Errors, bugs, questions - page 1135

 
Fleder:
Please post all your code.
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(const datetime 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                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
// 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_time
   Print("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
  }
 
Tron_KZ:
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:

   CFoo foo1(TimeCurrent());     // явный вызов параметрического конструктора
   CFoo foo2();                  // явный вызов параметрического конструктора с параметром по умолчанию
   CFoo foo3(D'2009.09.09');     // явный вызов параметрического конструктора
   CFoo foo4(foo1);              // явный вызов конструктора копирования
   CFoo foo5;                    // явный вызов конструктора по умолчанию (если конструктор по умолчанию отсутствует,
                                 // то вызывается параметрический конструктор с параметром по умолчанию)
 
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!
 
The OOP in mql5 seems to have undergone specific changes. On the sly...
 
C-4:
On what grounds have they cancelled conversion of non-constant objects to constant ones?

Everything compiles normally - no errors or warnings

class A {};
void f( const A& a ) {}
void OnStart()
{
        A a; //не const A
        f( a );
}
If there are any errors, it is only in struct, but they will get to them eventually
 
A100:

Everything 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.

class A 
{
   public:
      void PrintMyName(){printf("my name A");}
};

void f(const A* a)
{
   a.PrintMyName(); //Хренушки. Теперь PrintMyName должен быть константым.
} 

void OnStart()
{
        A a; //не const A
        f(GetPointer(a));
}

And now attention question: let's wipe the CObject.Compare():

virtual int  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!!!

 
mql5:
It is now mandatory to place static members.

And how are you supposed to place complex static objects if static constructors are not allowed?

class A 
{
   public:
      void PrintMyName(){printf("my name A");}
};

class B
{
   public:
      static A* a; //В этом месте как прикажете объект инициализировать? 
};
 
C-4:

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

void f(const A* a)

instead of

void f(A* a)
 
C-4:

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.

Um, this is actually the fancy way to do it.
 
C-4:

And how are you supposed to place complex static objects if static constructors are not allowed?

class A 
{
   public:
      void PrintMyName(){printf("my name A");}
};

class B
{
   public:
      static A* a;
};

A* B::a = new A;