Consider the following hierarchy of structs:
struct I1 {
virtual void doit() = 0;
};
struct I2 {
virtual void doit(int) = 0;
};
struct I12 : I1, I2 {
using I1::doit;
using I2::doit;
};
struct Derived : I12 {
void doit(int) override {}
};
Compiling this (using clang
, or g++
with -Woverloaded-virtual
) gives me a warning:
'Derived::doit' hides overloaded virtual function [-Woverloaded-virtual]
However, if I change I12
to the following, it compiles fine under clang
, while g++ -Woverloaded-virtual
still gives a warning:
struct I12 : I1, I2 {
using I1::doit;
void doit(int) override = 0;
};
Where is the difference between using I2::doit
and void doit(int) override = 0
? Naively, I would have thought that the former is sufficient to inform the compiler that I am aware that there are two versions of doit
.
using
-declaration inDerived
, but in my concrete case, I haveDerived1
,Derived2
, ..., and possibly evendoit1
,doit2
..., so I do not want to repeat all thoseusing
-declaratios everywhere, but if possible only at one central place. – Hitherdoit()
onDerived
, you have to do it for every derived class. Otherwise, you might need some help from compiler options. – Should