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 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.
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.
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++.
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) :)
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 ))
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.
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
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.
I meant an explicit copy operator and explained it in code.
I doubt the compiler separates them (in the code context) into explicit and implicit. Otherwise it would be easy to fix it
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) :)
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.
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 ))
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: