【发布时间】:2015-03-27 13:59:32
【问题描述】:
我的朋友给我发了一个有趣的任务:
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 };
};
我无法用 VS2013 编译这段代码。使用 GCC 4.9.0 可以编译。但我不明白它的作用。
我的兴趣点:
- 如果函数只有声明而没有定义,它如何工作?
-
TestT<T>::template test<T>(0)是什么?它看起来像一个函数调用。 -
::template是什么意思? - 以上课程的目的是什么?
- 用到的原理怎么叫?
-
int C::*是指向int成员的指针,对吧?
【问题讨论】:
-
吟唱 向伟大的老者致敬 SFINAE!