假设我有以下类:
struct baseA {
virtual int foo() {return 0;}
};
struct baseB {
virtual int bar() {return 1;}
};
struct derived : public baseA, public baseB {
typedef std::tuple<baseA, baseB> base_types;
virtual int buzz() {return 2;}
};
我想通过模板获取derived
的基类,我可以使用这样的代码:
template <typename T>
struct basetraits{
typedef T::base_types types;
};
std::tuple_element<0,basetraits<derived>::types>::type
std::tuple_element<1,basetraits<derived>::types>::type
如果我没有在base_types
类中定义derived
或使用某个宏,是否可以通过其他方法获取baseA
和baseB
?