检测类的类型
答
是:
template <typename T, typename U>
struct is_same
{
static const bool value = false;
};
template <typename T>
struct is_same<T, T>
{
static const bool value = true;
};
is_same<int, float>::value; // false
is_same<int, int>::value; // true
这些被称为类型特征,并且可以在Boost.TypeTraits和C++ 0x中找到他们的转换。
+0
哟我的男人!这是检测类型是否相同,而不是它们是某种类型。 – 2010-11-06 20:28:02
+1
@There:那么你的问题没有意义。如果你想知道“它们是否属于某种类型”,与检查“检测类型是否相同”有什么不同? [像往常一样](http://www.catb.org/esr/faqs/smart-questions.html),询问你想要解决的大局和问题,而不是你认为需要的微小理论步骤采取。 – GManNickG 2010-11-06 20:28:58
是的,这是可能的,但为什么? – kennytm 2010-11-06 20:26:12
你是指什么类的类?一个类是一个类型。 – sepp2k 2010-11-06 20:26:52
-1:就目前来看,这个问题没有意义。请澄清! – 2010-11-06 20:27:49