I am having problems with gcc-11 C++ compiler when using multiple inheritance and I want to call a specific method of the base class and I write using A::m1 explicitely. Visual C++ 2022 works with this code, however gcc-11 fails and produces an error. This is the code:
struct Base
{
void m1(){}
void m2(){}
void m3(){}
};
struct A: Base{};
struct B: Base{};
struct C: A,B
{
using A::m1;
void mc()
{
m1();
}
};
In MSVC++ 2022 it compiles ok, however gcc-11 fails with this error:
In member function 'void C::mc()': 'Base' is an ambiguous base of 'C' m1();
It is an error of GCC 11 compiler? how can overcome it? why it is not taking into account the using statement? new GCC versions solve this issue?
(Note: I know that replacing m1() by A::m1() works but I want to take benefit of "using")
Probably many of you think that using virtual inheritance with Base solve the problem, it is correct, but for some reasons I cannot use virtual inheritance in this case.
Another question, is there any way to take preference to ALL member of a base class instead of writing one by one with "using" statement, instead of writing:
using A::m1;
using A::m2;
using A::m3;
to write something like:
using A::Base
Any help is wellcome.
Regards Pedro
I tried to code with "using" in several ways but all of them failed with GCC 11 compiler
The answers in linked post do not answer why gcc compiler does not compile and MSVC++ compiles. It is not an alternative in gcc for compiling this exact piece of code?