小小的一個泛型題目

題目不難,不過覺得很好玩。

泛型定義如下:


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);


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章