Errors, bugs, questions - page 2328

 
Alexey Navoykov:
You're not paying attention.

Or you. Let's get right to the point.

 
A100:

I offered the simplest variant that could be implemented tomorrow (not in 10 years) and would be similar to C++ (otherwise why change anything at all). Moreover, if operator*() is not and will not be implemented (there was information about it on the forum), it is unclear why operator->() suddenly would be implemented (they are of the same order).

It is not needed in this form tomorrow or in 10 years. And you don't need external similarity, you need features.

To at least partially port STL from C++. It is not only operator-> that is at stake here, we need much more.

operator-> would be the first step towards smart pointers.


 

In fact, all is not well with implicit cast as it is now.

class A
{};

class B : public A
{};

void OnStart()
{
   A* ab = new B;
   A* aa = new A;
   
   B* bb = ab; // ok
   
   B* ba1 = dynamic_cast<B*>(aa);
   Print(ba1 ? "ba1 ok" : "ba1 bad cast"); // bad cast

   B* ba2 = aa; // здесь неконтролируемый вылет
   Print(ba2 ? "ba2 ok" : "ba2 bad cast");
}

You can see that dynamic cast is included in the implicit cast

BUT

first, we don't know why it's included when dynamic cast is explicitly present in the language.

secondly it is included very badly because dynamic cast error in case of function can be controlled (bad pointer output) but implicit cast cannot! because it throws an uncontrollable exception

2018.11.23 20:31:47.348 test (AUDNZD,M5) incorrect casting of pointers in 'test.mq5' (17,11)

It has no effect.

You either have to give an invalid pointer as a function, or exclude dynamic cast from the implicit cast and give a compilation error.

 

Yes, with this problem, working with OOP is poorly controlled and unreliable. Somewhere you change the type in one place of the program, and then it explodes in who knows where. In these examples, you can somehow get away with using crutches, because there is simple pointer assignment, and everything is in front of you. But in general, when a pointer is passed to some function and dynamically casts to something unknown, you have no way to control it.

 
Alexey Navoykov:

A point is a universal operator in MQL.

That depends on how you look at it. You can say it's universal: it works with both objects and pointers.

Or you can say that . works only with objects, and it works with pointers only insofar as the pointer is implicitly cast to the object, i.e. in the case of

class A {
public:
    void f() {}
} *a;

entry

    a.f();

is equivalent to not

    a->f();

a

    (*a).f();
 

there is this structure

struct OrdersInfo
{
   int      ticket;
   string   symbol;
   int      type;
   double   volume;
   double   open_price;
   double   stop_loss;
   double   take_profit;
   string   comment;
   int      magic;
};

there is a variable OrdersInfo order, when I try to write it into a file

bool WriteStr(OrdersInfo &order)
{
   int handle = FileOpen(m_file_name, FILE_WRITE | FILE_COMMON | FILE_BIN);
   if(handle != INVALID_HANDLE)
   {
      if(FileWriteStruct(handle, order) == 0) return false;
      
      FileClose(handle);
   }
   
   return true;
}

the compiler gives out: 'order' - structures containing objects are not allowed

What could be the problem?


 
Andrii Djola:

there is this structure

there is a variable OrdersInfo order, when I try to write it into a file

the compiler gives out: 'order' - structures containing objects are not allowed

What could be the problem?


Here

https://www.mql5.com/ru/docs/files/filewritestruct

lists the restrictions.

Документация по MQL5: Файловые операции / FileWriteStruct
Документация по MQL5: Файловые операции / FileWriteStruct
  • www.mql5.com
//|                                          Demo_FileWiteStruct.mq5 | //|                        Copyright 2013, MetaQuotes Software Corp. | //|                                             https://www.mql5.com | //| Структура для хранения данных свечи                              |...
 
Thank you
 

MT4 on UPU traffic is negative, downloaded history counter started to increase ...


 
When you go to any author's product page, there is no way to tell which products are for the right platform (4 or 5). Is it possible to divide the products on this page by platform?