Errors, bugs, questions - page 2327

 
Alexey Navoykov:

Why hasn't MQL fixed the bug that a base class is implicitly cast to a derived class? Not even a compiler warning!

It must be because of this correct construct

class A {  };

class B : public A { };

A* a;

B* b= a;  // Нет ошибки

was not taken into account.

 
fxsaber:

Probably because of this correct design

has failed to take yours into account.

This is exactly the same incorrect construction.
 
Alexey Navoykov:
It is exactly the same incorrect construction.

If there is a derived class object behind a pointer to a base class, that's a great construction.

 
fxsaber:

If there is a derived class object behind the pointer to the base class, this is a great design.

I suggest you don't argue and just believe me that this is a mistake.
 
Alexey Navoykov:
I suggest not to argue, but just believe me that it is a mistake.

This verb is weakly applicable in a technical forum. Tried C++.

class A {  };

class B : public A { };

A* a = new B;

B* b= dynamic_cast<B*>(a); // cannot dynamic_cast ‘a’ (of type ‘class A*’) to type ‘class B*’ (source type is not polymorphic)
B* b1= a; // invalid conversion from ‘A*’ to ‘B*’ [-fpermissive]

None of the options worked. The reasons are not clear.

 
Koldun Zloy:

If you make them interchangeable, then they are both just unnecessary.

In C++, this is possible:

I suggested the simplest variant which could be implemented tomorrow (not in 10 years) and would have an external resemblance 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->() would be suddenly implemented (they are of the same order).

 
Alexey Navoykov:

Why hasn't MQL fixed the bug that a base class is implicitly cast to a derived class? Not even a compiler warning!

Are you waiting for a compilation error? There shouldn't be one, because in this case it is dynamic_cast
 
TheXpert:
Are you waiting for a compilation error? There shouldn't be one, because in this case it's dynamic_cast
See above, fxsaber provided the C++ code.
 
Alexey Navoykov:
See above, fxsaber provided the C++ code.

compiled by

class A 
{ 
public:
    virtual ~A() = default; 
};

class B : public A { };

int main(void)
{
    A* a = new B;
    B* b= dynamic_cast<B*>(a);
    return 0;
}
 
TheXpert:

compiled by

You're not paying attention.