Errors, bugs, questions - page 1087

 

The abbreviated notation of the postfix operator++ does not compile when an explicit conversion of a base class pointer to a derived

class A {
};

class B : public A {
public:
        void    operator++( int ) {}
        void    operator++()      {}
};

void f( A* a )
{
        ((B *)a).operator++( 0 ); //нормально
        ((B *)a).operator++();    //нормально
        ++((B *)a);               //нормально
        ((B *)a)++;               //ошибка
}
 
At least the compiler should warn that a.f() is not const
class A {
public:
        int f() { return ( 1 ); }
};

class B {
public:
                B( const A *aa ) : a( aa ) {}
        int g() { return ( a.f() ); } //должно быть предупреждение, поскольку a.f() не const
        const A *a;
};
 
A100:
At least the compiler should warn that a.f() is not const
Thank you for your diligence, both errors have been corrected.
 
mql5:
Thanks for the heads up, both errors have been corrected.
Only the last one is not technically an error - only a warning should be. It is only an error if
class B {
public:
        A * const a;
};

But in the templates. I'll give you examples later.

 

Here too - it's not clear.

class A {
public:
};

void ex1( const A* &t1, const A* &t2 )
{
        const A* t = t1;
        t1 = t2;
        t2 = t;
}

void OnStart()
{
    const A *a1 = new A(), *a2 = new A();
    Print( "Было :" a1, " ", a2 ); // Было :1 2
    ex1( a1, a2 );
    Print( "Стало:"  a1, " ", a2 ); // Стало:2 1
    delete( a1 );
    delete( a2 );
}

everything works correctly, but if you add the intermediate function ex2(...)

void ex2( const A* &t1, const A* &t2 ) { ex1( t1, t2 ); }

void OnStart()
{
    сonst A *a1 = new A(), *a2 = new A();
    Print( "Было: ", a1, " ",  a2 ); // Было :1 2
    ex2( a1, a2 );
    Print( "Стало:",  a1, " ",  a2 ); // Cтало:2 2           <-----
    delete( a1 ); delete( a2 );
}

The result is different. What did ex2(...) do ? - just passed the pointers by reference on

Please take a look at

 
A100:

Here too - it's not clear.

everything works correctly, but if you add the intermediate function ex2(...)

The result is different. What did ex2(...) do ? - just passed the pointers by reference on

Please take a look at

Thanks, language optimizer error, fixed.
 

It's not the first time, but it's the only time you get such photos when uploading, which means you have to set some criteria (you probably have a certain size).
). They are displayed normally everywhere else. Please tell me what's wrong.


 
An unnecessary compilation error occurs if the macro uses a result type conversion and the return value is then not used (sometimes it is needed, sometimes it is not)
int g( int x ) { return ( x ); }

#define  F( X )    (long)g( X )

void OnStart()
{
        int f = F( 0 ); //нормально
        F( 0 );         //ошибка компиляции
}
 
A100:
An unnecessary compilation error occurs if a macro uses a result type conversion, and the return value is not subsequently used (sometimes it is needed, sometimes not)

This has nothing to do with the use of defines.

A simple define equivalent will also give the same error

(long)g(0);


'(long)' - expression has no effect


P.S. Now there will be a vorning here.

 

After recompiling the indicator, the "array out of range" error started to occur when working with dynamic arrays.

It didn't occur before. What to do?

Документация по MQL5: Основы языка / Типы данных / Объект динамического массива
Документация по MQL5: Основы языка / Типы данных / Объект динамического массива
  • www.mql5.com
Основы языка / Типы данных / Объект динамического массива - Документация по MQL5
Reason: