I'm trying to do SFINAE on a constructor. I want to enable one overload for integers and one for everything else. I know I can just make a base(int)
and base(T)
constructor but I want to do it this way instead.
template <class T>
struct base
{
template <class T1 = T>
base(T1, typename std::enable_if<std::is_same<T1, int>::value>::type* = nullptr) {}
template <class T1 = T>
base(T1, typename std::enable_if<!std::is_same<T1, int>::value>::type* = nullptr) {}
};
Then I make a main Base
class that inherits the constructors:
template <class T>
struct Base : base<T>
{
using base<T>::base;
};
But when I instantiate Base
with any T
I get these errors:
source_file.cpp:21:15: error: call to deleted constructor of 'Base<int>'
Base<int> v(4);
^ ~
source_file.cpp:16:25: note: deleted constructor was inherited here
using base<T>::base;
^
source_file.cpp:7:5: note: constructor cannot be inherited
base(T1, typename std::enable_if<std::is_same<T1, int>::value>::type* = nullptr) {}
^
When I instantiate base
directly it works without a problem. Why can't the constructor be inherited when I am doing SFINAE? Without the second constructor overload everything works fine.