Errors, bugs, questions - page 2466

 

Logical error

void f( const int  ) {}
void f( const int& ) {}
void OnStart()
{
          int i = 0; f( i ); //(1) нормально
    const int j = 0; f( j ); //(2) Error: 'f' - ambiguous call to overloaded function with the same parameters
}

What is the difference between (1) and (2) ?

 
A100:

Logical error

What is the difference between (1) and (2) ?

There seems to be an error in the 1st one. And the 2nd one can be bypassed by j+0.

 
fxsaber:

There seems to be an error in the 1st one. And the 2nd one can be bypassed by j+0.

Why do we need an extra arithmetic operation when we can do without it?

        const int j = 0; f((int)j);
 
A100:

Why the extra arithmetic operation?

It won't be there after compilation.

 
fxsaber:

It won't be there after compilation.

It will. It's just that in the general case, the compile-time error will move into the run-time error:

void f( const int  ) { Print( 1 ); }
#define  int short
//...
void f( const int  ) { Print( 2 ); }
void f( const int& ) { Print( 3 ); }
void OnStart()
{                     //Результат:
          int i = 0; f( i   );  //2
    const int j = 0; f( j+0 );  //1
}

Result: 2:1

And in my version: 2:2

void OnStart()
{                     //Результат:
          int i = 0; f( i   );  //2
    const int j = 0; f((int)j); //2
}
 
A100:

It will. It's just that in general, a compile-time error will move into a run-time error:

Result: 2:1

The result is mixed up in the source. I don't think there is a runtime addition. It's just the compiler calls the int-function for the expression. But it does not calculate the expression itself.

 

Was thinking of implementing an iterator analogue for C++. But a sadness arose....


Question for developers:
Which of the unary operators allowed in MQL is suggested as best practice for implementing a dereferencing operation?

  • unary +,-,++,--,!,~
 
Sergey Dzyublik:

Which of the unary operators allowed in MQL is suggested as best practice for implementing a dereferencing operation?

  • unary +,-,++,--,!,~

Wow, there are some people here on this forum that think about best practice.

The most logical thing to do is shift, for lack of it. (sorry, it requires a parameter, then addition as the seldom used one) But will it work ok with even one?

At most we can get it this way:

(~w).F();

You'll always have to bracket it because of the point priority.

 
Sergey Dzyublik:

Question for developers:
Which unary operator overloading allowed in MQL is suggested as best practice for implementing dereferencing operation?

  • unary +,-,++,--,!,~

what can be dereferenced in MQL ? - even pointers to objects are dereferenced when accessed by pointer name

SZZY: I wish you could channel your energy into something useful.... Last month, for the umpteenth time I tried to make a wrapper class for a two-dimensional array, I couldn't manage to overload [] to address as a normal two-dimensional array arr[1][2], and you're talking about dereferencing pointers in MQL ...

 
Igor Makanu:

I haven't managed to overload [] to address as a normal two-dimensional array arr[1][2], and you're talking about pointer dereferencing in MQL...

it happens )))