模板类型检查C ++ [英] Template type check C++
本文介绍了模板类型检查C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个接受对象的模板函数。我需要确定对象是否派生自特定的基类。如果它是从基类派生的,我需要调用额外的函数。有没有我可以在C + + Linux?
I have a template function which takes in objects. I need to determine whether the object is derived from a particular base class. If it is derived from the base class, I need to call additional function. Is there anyway I could do it in C++ Linux?
class baseA{
};
class derivedA:baseA{
};
class testB{
};
template<typename T>
void functionA(const T& value){
//if T is derived from baseA, call an additional function
//perform common operations for derivedA and testB...
}
derivedA中的成员函数,但不在testB中。
To clarify, the additional function is a member function in derivedA but not in testB.
推荐答案
Boost.TypeTraits
boost :: is_base_of
Boost.TypeTraits boost::is_base_of
const bool is = boost::is_base_of<Base,Derived>::value;
这篇关于模板类型检查C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文