I'm trying to use SFINAE to distinguish a class that has a member called 'name'. I set things up in what seems to be the standard pattern but it's not working -- instead of silently ignoring the 'failed' substitution, the compiler produces an error.
I'm sure I've run up against some template substitution rule, I'd be grateful if someone could explain which one.
This is a stripped down example. I'm using gcc:
template <typename U> string test( char(*)[sizeof(U::name)] = 0 ) { return "has name!"; }
template <typename U> string test(...) { return "no name"; }
struct HasName { string name; }
struct NoName {}
cout << "HasName: " << test<HasName>(0) << endl; //fine
cout << "NoName: " << test<NoName>(0) << endl; //compiler errors:
//error: size of array has non-integral type `<type error>'
//error: `name' is not a member of `NoName'