I have the following code:
struct CommonVariables
{/*some common variables that need to be proceed*/};
struct CommonHandler
{
static void foo(const CommonVariables& vars) {/*processed vars*/}
void bar(const CommonVariables& vars) {/*processed vars*/}
};
struct AnotherVariables
{/*another variables*/};
struct AnotherHandler
{
static void foo(const AnotherVariables& vars) {/*processed vars*/}
void bar(const AnotherVariables& vars) {/*processed vars*/}
};
struct Derived : CommonHandler, AnotherHandler
{};
And when I try to call Derived::foo(/any variable type/) or Derived d; d.bar(/any variable type/), the compiler gives me an error: "reference to 'foo(or bar)' is ambiguous".
Yet below I have almost the same situation:
struct DifferentHandler
{
static void foo(const CommonVariables& vars) {}
static void foo(const AnotherVariables& vars) {}
void bar(const AnotherVariables& vars) {}
void bar(const CommonVariables& vars) {}
};
And calling DifferentHandler::foo(/any variable type/) or 'bar' works just fine.
There are plenty of solutions to work around the first code block (template traits, etc.). What I specifically want is to overload methods through inheritance. And I don't understand why calls from Derived are ambiguous (since input parameters have different types, from compiler point of view those functions are different. Like in DifferentHandler)
NOTE: I've tried MinGW5.8 (in Qt Creator), and MSVC2015 in VS2015. Both compilers generated same error.