maybe this is a FAQ, but all exisiting questions I found were referring to methods with identical signature, i.e. real overrides.
My problem boiled down to a minimal example:
class A
{
public:
enum class Enumeration {Value_1, Value_2};
void SetValue(Enumeration e) //!! this is what it is about
{
m_member = e;
}
Enumeration m_member;
};
class B
{
public:
void SetValue(std::string value) // same method name, different parameter type -> different method signature
{
m_stringMember = value;
}
std::string m_stringMember;
};
class C : public A, B // inheriting both SetValue() methods
{
};
int main(int argc, char **)
{
C test;
test.SetValue(A::Enumeration::Value_1); // C2385 - ambiguous access
test.SetValue("Test"); // C2385 - ambiguous access
}
Compiler: VC++ 15
The call to both test.SetValue() functions gives me a C2385:
error C2385: ambiguous access of 'SetValue'
note: could be the 'SetValue' in base 'A'
note: or could be the 'SetValue' in base 'B'
Regarding the error message, I object. It "could not" be the SetValue in the other base class because the parameter type mismatches. It should be clear to the compiler which method matches the call.
Obviously (verified), overloading works fine if I put both methods into class A and instantiate A:
class A
{
public:
enum class Enumeration {Value_1, Value_2};
void SetValue(Enumeration e)
{
m_member = e;
}
void SetValue(std::string value)
{
m_stringMember = value;
}
Enumeration m_member;
std::string m_stringMember;
};
int main(int argc, char **)
{
A test;
test.SetValue(A::Enumeration::Value_1);
test.SetValue("Test");
}
What makes the difference here? How do these two method declarations interfere? Is there a way of overcoming this which does not require changing the name of SetValue() in one of C's base classes?