Errors, bugs, questions - page 2356
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
in C++: A::f()
What does this code say?
What does this code say?
It's the same.
Same thing.
That and MQL (assuming it is converted to C++ form). But you could have checked it yourself
Checked:
Checked:
I think you are checking something wrong.
Such an entry in MQL means copying of an object a - to an object located by pointer b1. In general, of course, it should not compile.
And in order not to mix up objects and pointers, you'd better use the p prefix for pointers
Checked:
Please don't be pawned off on this misguided behaviour.
There are 2 problems here(?):
the virtual B::f() is not overloaded, so instead of a virtual call it was a simple call, B::f() has no member addressing, so access by "pointer" was also cut out
In the second case, A::f() is an attempted virtual call, there is access by "pointer", but no a1 object, because an empty copy constructor A::A(const A &) was also called for A *a1=b
Please don't bank on this misguided behaviour.
There are 2 problems here(?):
I hope you will fix this erroneous behaviour? (make a compilation error) Because it is possible to make such an error by accident and the compiler does not react in any way.
I hope you will fix this erroneous behaviour? Because it's possible to make such an error by accident and the compiler doesn't react in any way.
Yes, we will fix it.
The priority is set low because only empty classes get working code
Please don't bank on this misguided behaviour.
There are 2 problems here(?):
the virtual B::f() is not overloaded, so instead of a virtual call it was a simple call, B::f() has no member addressing, so access by "pointer" was also cut out
In the second case, A::f() is an attempted virtual call, there is access by "pointer", but no a1 object, because an empty copy constructor A::A(const A &) was also called for A *a1=b
Thanks for the detailed answer, however, I'm a bit confused about the logic.
1) Why does the compiler see the construct B* b1=a as a call of the copy operator A::A(const A&), (instead of calling B::B(const A&), because it is class B to the left of operator=)
2) Why didn't the compiler generate the warning "copy constructor missing"?
3) why a "simple" method call is allowed for non-existing objects (while an attempt to call B::f() directly gives a compilation error "not a static method call")
4) And why does the compiler allow a "simple" virtual method call at all? In my opinion, virtuality should not depend on presence or absence of data in the object
1) Why does the compiler see B* b1=a as a call to copy operator A::A(const A&), (instead of calling B::B(const A&), because it is class B to the left of operator=)
That's exactly right. This is another MQL bug, that the compiler freely allows such things: B b = a; This is a violation of encapsulation principles. In C++ such things do not compile naturally, an explicit conversion is required. And in old MQL builds such things could not be done as well.