題目不難,不過覺得很好玩。
泛型定義如下:
template<bool b, class X, class Y>
struct if_
{
typedef X type; // use X if b is true
};
template<class X, class Y>
struct if_<false,X,Y>
{
typedef Y type; // use Y if b is false
};
(題目原型摘抄自:http://blog.csdn.net/pongba )
請問len是多少,當地一個參數爲false或者爲true的時候:
int len = sizeof(if_<false,short,int>::type);