I have a template class in C++ (somewhat simplified):
template<typename T>
struct C
{
T member;
void set(const &T x) { member = x; }
void set(int x) { member = x; }
};
As you can see the set() function can be called either with the type T, or with an int. This works fine unless T is an int, in which case I get an ambiguous conversion error. I understand why this is happening, but is there any way to implement what I want?
One way around this would be to provide a specialisation of the template for
intthat only has one set function. Otherwise you might want to have a look at the Boost libraries if something likeenable_ifin their template meta programming code would allow you to turn on the functionset(int x)only when T is not of type int.