As an experiment, I am trying to make a void member function with no parameters change behavior based on the class template parameter:
#include <iostream>
#include <limits>
template<typename T>
class MyClass
{
public:
void MyFunc(const typename std::enable_if<std::is_fundamental<T>::value, T> dummy = T());
void MyFunc(const typename std::enable_if<!std::is_fundamental<T>::value, T> dummy = T());
};
template<typename T>
void MyClass<T>::MyFunc(const typename std::enable_if<std::is_fundamental<T>::value, T> dummy)
{
}
template<typename T>
void MyClass<T>::MyFunc(const typename std::enable_if<!std::is_fundamental<T>::value, T> dummy)
{
}
class Simple {};
int main(int argc, char *argv[])
{
MyClass<int> myClass;
myClass.MyFunc();
// MyClass<Simple> myClass2;
// myClass2.MyFunc();
return 0;
}
However, I am getting: error: call of overloaded ‘MyFunc()’ is ambiguous. Shouldn’t only one or the other of those functions get defined, since everything is the same except for a ! in one of them?
You have to make dummy template parameters to do what I was asking: