Is it possible to make an overload of a constructor which will accept only a blank string when used in an initializer list?
struct null_ptr_type;
struct str
{
str(null_ptr_type*) {}
str(const char(&)[1]) {}
};
struct config
{
str s;
};
int main()
{
config c1 = {0}; // Works, implicit conversion to a null pointer
config c2 = {str("")}; // Works
config cx = {str("abc")}; // Fails (as desired)
config c3 = {""}; // Fails with no conversion possible
}
Is there a way to make the syntax for c3
work without also accepting non-empty strings? I don't see why it doesn't, given that c1
works. Is there some rule I'm missing here that forbids this?