On Wed, 23 Sep 2009, Jean-Louis Leroy wrote:
Consider :
template<typename U> struct Test { template<typename T> typename enable_if
, void>::type test() { cout << "int" << endl; } template<typename T> typename enable_if
, void>::type test() { cout << "char" << endl; } }; template<typename T> typename enable_if
, void>::type test() { cout << "int" << endl; } template<typename T> typename enable_if
, void>::type test() { cout << "char" << endl; } int _tmain(int argc, _TCHAR* argv[]) { test<int>(); test<char>(); Test<int>::test<double>(); // error return 0; }
MSVC9 will give a compilation error (see below) where marked. Am I missing something obvious ?
For one thing, your functions are not static. The actual problem is that SFINAE applies to template argument deduction, and does not work with explicitly specified template arguments. You would need to have T deduced in each of the member functions to have SFINAE (and thus enable_if) work. -- Jeremiah Willcock