如何检查我的模板类是一个特定的classtype? [英] How do I check my template class is of a specific classtype?

查看:100
本文介绍了如何检查我的模板类是一个特定的classtype?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的模板化函数中,我试图检查类型T是一个特定类型。我会怎么做?

In my template-ized function, I'm trying to check the type T is of a specific type. How would I do that?

p / s我知道模板规范的方式,但我不想这样做。

p/s I knew the template specification way but I don't want to do that.

template<class T> int foo(T a) {
  // check if T of type, say, String?
}

谢谢!

推荐答案

我想您可以使用 <$ c $由typeid运算符返回的 std :: type_info

I suppose you could use the std::type_info returned by the typeid operator

这篇关于如何检查我的模板类是一个特定的classtype?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆