Errors, bugs, questions - page 2359

 
A100:

I double-checked it especially for you, taking into account

It's OK DJ.

What compiler do you use?

I'm on VS 2010:

binary '=' : no operator found which takes a right-hand operand of type 'A' (or there is no acceptable conversion)

p.s. I just don't really understand what "with consideration" means? It was about the acceptability of implicitly copying a base class into a derived class.

 

In Visual Studio, my example works too. I meant the explicit copy operator and explained it by the code.

I wrote it just in case, so that if you disable the explicit one, you won't accidentally disable it at the same time

 
A100:

In Visual Studio, my example works too. I meant the explicit copy operator and explained it by the code.

I wasn't referring to the explicit operator. I was speaking about the inadmissibility of the implicit operator in this case which you called "narrow-mindedness" and it's not so.

If you need to make a copy, you must first explicitly cast b to the correct type in C++. For such a copying is a violation of object encapsulation. That's why the implicit type should be completely out of the question.

 
A100:

I meant an explicit copy operator and explained it in code.

By the way, if class A also inherits from some class X, then your class B is in no way protected from copying X (we are talking about MQL). You have to write operators for ALL parent classes.
 
A100:

I doubt the compiler separates them (in the code context) into explicit and implicit. Otherwise it would be easy to fix it

The point is that an implicit operator always corresponds to an object's type. I.e. if an object is of type B, its implicit operator is of type const B&. It does not take type A. But this is C++.
 

By the way, the operator type seems to be OK

First it looks for operator B::, if it's absent, then it looks for operator A::, if it's absent there too, then it considers its duty done and does nothing (although the pointer is broken as a result) :)

 
Ilya Malev:

if it's not there either, then it considers its duty done and does nothing (although the pointer is eventually broken) :)

Why doesn't it do anything? It copies by implicit (automatic) operator=(const A&), which it should not do.

And finally remove that asterisk after B, it hurts your eyes ) We have already figured out everything with this bug.

 
Alexey Navoykov:

And finally take away that asterisk after B, it hurts the eye ) It's already figured out everything with this bug.

I personally find object variables without asterisks disturbing )) One of the nasty bugs is to write A a=new A instead of *a and not understand what's wrong for a long time) I, on the contrary, showed that everything works correctly if you follow your advice and declare a private op.=&. The editor will produce an error in this case at once. I'll do it that way from now on ))

 
Spent a few hours searching for discrepancies. Found this
#define  PRINT(A) Print(#A + " = " + (string)(A))

void OnStart()
{
  const double Koef =  0.25;
  const int iDelta = 32;
  const double point = 0.00001;
  
  const double high = 1.06736;
  const double low = 1.06676;
  
  const double Avg = (high + low) * 0.5;  
  const double Size = (high - low) * Koef * 0.5;  
  
  PRINT(DoubleToString(Avg - Size - point * iDelta, 5));   // DoubleToString(Avg-Size-point*iDelta,5) = 1.06666
  PRINT(DoubleToString(Avg - (Size + point * iDelta), 5)); // DoubleToString(Avg-(Size+point*iDelta),5) = 1.06667
} 


The peculiarities double know, but not such that if you change the order of addition (except for the relatively very different numbers), the result is different! Please explain to a fool why this happens here?

You only need to look at the bottom two lines in the source.

 

Error for developers.

The script does not compile, identify why))). Use attached file.


Same file:


Files:
Test1.mq5  9 kb