Basically I want to have multiple member functions with same name, but different signature, spread in multiple base classes.
Example:
#include <iostream>
struct A
{
void print(int) { std::cout << "Got an int!" << std::endl; }
};
struct B
{
void print(double) { std::cout << "Got a double!" << std::endl; }
};
struct C : A, B {};
int main()
{
C c;
c.print((int)0);
return 0;
};
But I got this error on clang:
main.cpp:18:7: error: member 'print' found in multiple base classes of different types
c.print((int)0);
^
main.cpp:5:10: note: member found by ambiguous name lookup
void print(int) { std::cout << "Got an int!" << std::endl; }
^
main.cpp:10:10: note: member found by ambiguous name lookup
void print(double) { std::cout << "Got a double!" << std::endl; }
Why is it ambiguous? Even with different number of arguments I get the same error.
Is there any workaround to get similar behavior?
c.print((int)0)
"0
is a literal of typeint
, you don't need to add(int)
here – Jahdai