Who is solving the problem now, when a template method in a template class is not found by the compiler for some reason and an error occurs?
no one of overloads can be applied to the function call
?
C compilers in such cases write specifically what types were substituted and what functions with what prototype are not found, so it is more or less clear what the problem is, but here - no specifics.
I would like to see the exact rule: when do I have the right to override a virtual function with a different type of return value?
Only one single case, when returning a pointer to a class object, when the return type of the overridden function inherits (is the first parent in multiple inheritance, not yet supported in MQL) from the type that the overridden one returns.
Ilyas: You have an error in your example - no inheritance of D from C
Yes, my mistake, sorry.
class A {};
class B : A {};
class C {
virtual B *f() { returnNULL; }
};
class D : C {
virtual A *f() { returnNULL; } //Error: overriding virtual function with different return type
};
class C;
class A {
virtual A *f() { returnNULL; }
};
class B : A {
virtual C *f() { returnNULL; } //Error: overriding virtual function with different return type
};
class C : B {
virtual C *f() { returnNULL; } //нормально
};
Ilyas: Despite the error (because there will be no executable generation), function B::f overrides A::f, so there is no override error for C::f.
I don't quite get the idea, but it's almost the same
class C;
class A {
virtual A *f() { returnNULL; }
};
class B : A {
virtual C *f() { returnNULL; } //Error: overriding virtual function with different return type
};
class C : A {};
class C;
class A {
virtual A *f() { returnNULL; }
};
class C : A {};
class B : A {
virtual C *f() { returnNULL; } //нормально
};
There is an error in one case and no error in the other. And I just swapped the lines
Who is solving the problem now, when a template method in a template class is not found by the compiler for some reason and an error occurs?
no one of overloads can be applied to the function call
?
C compilers in such cases write specifically what types were substituted and what functions with what prototype are not found, so it is more or less clear what the problem is, but here - no specifics.
We did this deliberately, as there is no problem with direct inheritance.
I'd like to see the exact rule: when do I have the right to override a virtual function with a different type of return value?
Or is it an overload?
I would like to see the exact rule: when do I have the right to override a virtual function with a different type of return value?
Thank you. It all makes sense.
...when the return type of an overridden function is inherited ... from the type returned by the overridden one.
What if it's the other way around?
What if it's the other way around?
You have an error in your example - no inheritance of D from C
Yes, my mistake, sorry.
Another controversial example:
Another controversial example:
Despite the error (because there will be no executable generation), function B::f overrides A::f, so there is no override error for C::f.
I don't quite get the idea, but it's almost the same
There is an error in one case and no error in the other. And I just swapped the lines