Why is this compiling:
class Testable {
public:
template <bool flag>
typename std::enable_if<flag>::type
void foo() { cout << "Yay" << endl; }
template <bool flag>
typename std::enable_if<!flag>::type
void foo() { cout << "Nay" << endl; }
};
But not if I define both foos using the default types, for example:
template <bool flag, typename = typename std::enable_if<flag>::type>
void foo() { cout << "Yay" << endl; }
template <bool flag, typename = typename std::enable_if<!flag>::type>
void foo() { cout << "Nay" << endl; }
I get this error (the first line points to the definition (B), the second points to (A)):
error: 'template<bool flag, class> void Testable::foo()' cannot be overloaded
error: with 'template<bool flag, class>> void Testable::foo()'
Barry source
share