I'm just starting my journey into more advanced template code. Consider the following...
template <typename T>
class node_base
{
public:
T member;
node_base() {}
void do_the_thing(node_base& other)
{
std::cout << other.member;
}
};
template <typename ...Args>
class node : public node_base<Args>...
{
public:
node() :node_base<Args>()...{}
};
int main()
{
node<int> int_node;
node<int, double> double_node;
int_node.do_the_thing(double_node);
double_node.do_the_thing(int_node); // ambiguous call
std::cin.ignore();
return 0;
}
Using Visual Studio 2017 15.4.5, I get the following...
error C2385: ambiguous access of 'do_the_thing' note: could be the 'do_the_thing' in base 'node_base' note: or could be the 'do_the_thing' in base 'node_base'
My understanding is that the compiler should be able to deduce the correct function based on the argument, in this case node<int>. Why is this call considered ambiguous? What can I do to clarify the call while still maintaining this template pattern?
template.cpp:31:17: error: member 'do_the_thing' found in multiple base classes of different typesnode<int, double>to anothernode<int, double>or similar scenarios?