I have the following code:
struct A{}; struct Base { virtual A& internal() = 0; }; struct Derives : public Base { auto& internal() override {
This is not compiled (tested on coliru - with gcc) with a conflicting return type - my question is why the compiler cannot determine that both internal_ (and therefore return type) A ? Is the type deduced for auto at a different compilation stage, for example, than the one that checks for virtual overrides? Of course, this compiles if you replace auto with the correct type, but that does not apply to the point.
(Here is the clang error, gcc is somewhat similar)
main.cpp: 8: 11: error: the return type of the virtual function is "internal" not covariant with the return type of the function that it overrides ('auto & amp; "is not inferred from" A & ")
auto& internal() override {
main.cpp: 4: 16: note: overridden virtual function here
virtual A& internal() = 0; ~~ ^
1 error generated.
c ++ c ++ 14
Nim
source share