The friend of mine send me an interesting task:
template<typename T>
class TestT
{
public:
typedef char ONE;
typedef struct { char a[2]; } TWO;
template<typename C>
static ONE test(int C::*);
template<typename C>
static TWO test(...);
public:
enum{ Yes = sizeof(TestT<T>::template test<T>(0)) == 1 };
enum{ No = !Yes };
};
I can't compile this code with VS2013. With GCC 4.9.0 it compiles. But I can't understand what it does.
The points of interest for me:
- How it can work if functions have a declaration only but no definition?
- What the
TestT<T>::template test<T>(0)
is? It looks like a function call. - What is this
::template
means? - What's purpose of class above?
- How is used principle called?
int C::*
is a pointer to aint
member, right?