Why this works (Templates, SFINAE). C++
- by atch
Hi guys, reffering to yesterday's post,
this woke me up this morning. Why this actually works? As long as the fnc test is concerned this fnc has no body so how can perform anything? Why and how this works? I'm REALLY interested to see your answers.
template<typename T>
class IsClassT {
private:
typedef char One;
typedef struct { char a[2]; } Two;
template<typename C> static One test(int C::*); //NO BODY HERE
template<typename C> static Two test(…); //NOR HERE
public:
enum { Yes = sizeof(IsClassT<T>::test<T>(0)) == 1 };
enum { No = !Yes };
};
Thanks in advance with help to understand this very interesting fenomena.