Errors, bugs, questions - page 2200

 

What does this mean?

2018.04.24 14:02:21.721 Books   invalid book item[Si-6.18,buy,61996.00000,-50]
 
fxsaber:
Why does the script not output anything?
because it is a pointer transfer and not a value transfer
 
Комбинатор:
because it is by reference and not by value

I don't understand it at all. Here is the code

class A
{
public:
  template <typename T>
  void operator =( T& ) // Без ссылки работает
  {
    Print(__FUNCSIG__);
  }
  
  void operator =( int )
  {
    Print(__FUNCSIG__);
  }
};

void f( A*& )
{
  Print(__FUNCSIG__);
}

void OnStart()
{
  A* a = new A;  
  
  A b;  
  b = a; // cannot convert type ' *' to reference of type 'A *'
  
  a = a;
  a = 1;
  
  f(a);
  
  delete a;
}

It somehow complains about passing a pointer by reference. At the same time, the f function calmly receives the pointer by reference.


The result is

void A::operator=<A*>(A*)
void A::operator=(int)
void f(A*&)

The int operator was called without any problems, while the pointer operator was not.

 
Logically, it shouldn't work without a reference either (imho). this may be a feature of mql pointers - that they don't need to be dereferenced
 
Комбинатор:
Logically it shouldn't work without reference (imho). It may be a feature of mql pointers - they don't need to be dereferenced.

A request to everyone who understands the subject, let's find out. It's a bit of a mess right now.

I used to think that an operator was just one of the methods that was convenient to use because of its syntax. And no other distinction. Now it turns out that's not always the case.

 
fxsaber:

I used to think that an operator was just one of the methods

any operator yes. but

1. operator = one of the most popular

2. the only operator which is generated by the compiler

 
Комбинатор:

any operator yes. but

1. operator = one of the most demanded

2. the only operator that is generated by the compiler

So overloaded/overridden operator.

 

I was wrong, it should work without the link. it means it doesn't work with the link because of the substitution nuances.

In pluses it works even with a reference.

If you have questions about such things, it is better to check with a benchmark, i.e. C++. however, syntax may be slightly different

operator_fxsaber, C++ (gcc) - rextester
  • rextester.com
operator_fxsaber in C++ (gcc)
 
Комбинатор:

I was wrong, it should work without the link. it means it doesn't work with the link because of the substitution nuances.

It works in the pluses and with a link.

If you have questions about such things it's better to check with a benchmark, i.e. C++. though the syntax may be slightly different

Thank you! Unfortunately, I don't speak any languages other than MQL. I also have a poor understanding of MQL. I'm learning OOP in MQL.

 

At first I thought I didn't know arithmetic at all.


How could these two numbers add up to 138.95, and how could adding two zeros add up to -24.34?

But then I realised:

If positions opened yesterday or earlier are closed today, they will not be displayed, but they do participate in the calculation of the amount of closed positions.

If you change the depth of the history displayed and then select "Today" again, all lost positions will return to their place.


Will this bug be fixed? Or no one needs it?