Errors, bugs, questions - page 1639

 

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.

 
Ilyas:
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?

 
Koldun Zloy:

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.
 

Thank you. It all makes sense.

 
Ilyas:
...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?

class A {};
class B : public A {};
class C {
        virtual B *f() { return NULL; }
};
class D {
        virtual A *f() { return NULL; } //нормально
};
 
A100:

What if it's the other way around?

You have an error in your example - there is no inheritance of D from C
 
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() { return NULL; }
};
class D : C {
        virtual A *f() { return NULL; } //Error: overriding virtual function with different return type
};
 

Another controversial example:

class C;
class A {
        virtual A *f() { return NULL; }
};
class B : A {
        virtual C *f() { return NULL; } //Error: overriding virtual function with different return type
};
class C : B {
        virtual C *f() { return NULL; } //нормально
};
 
A100:

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.
 
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() { return NULL; }
};
class B : A {
        virtual C *f() { return NULL; } //Error: overriding virtual function with different return type
};
class C : A {};
class C;
class A {
        virtual A *f() { return NULL; }
};
class C : A {};
class B : A {
        virtual C *f() { return NULL; } //нормально
};
There is an error in one case and no error in the other. And I just swapped the lines
Reason: