I'm trying to derive from a class which doesn't have a constructor from int
but does from a nullptr
, trying to make the constructor in derivative as generic as possible when it takes a single argument. But for some reason the correct constructor doesn't appear to be taken, even if substitution of int
into template constructor results in a failure:
#include <cstddef>
#include <iostream>
struct Base
{
Base(std::nullptr_t){}
Base(){}
// some other constructors, but not from int
};
struct Test : Base
{
Test(std::nullptr_t) : Base(nullptr)
{
std::cerr << "Test(nullptr)\n";
}
template<typename T>
Test(T v) : Base(v) {}
};
int main()
{
Base b=0; // works
Test z=nullptr; // works
Test t=0; // compilation error
}
Why does it happen? Is it not what SFINAE is supposed to mean? And how can I fix this problem?