如何解决是否有一种编译时方法来断言基类是“第一个”并且在 C++ 中与子类的偏移量为 0
class MiClass : public Base1,public Base2 {
};
// assuming all base classes have a virtual destructor.
// I want a compile time test to determine if the offset of Base1 in MiClass
// is 0 at compile time so a template will fail to compile if the offset of
// the base is NOT 0 ie: so in the compile time assert Base1 will be ok
// but testing Base2 will fail.
// to assert that:
void *vp = xxx; ( assume a valid pointer to an MiClass )
MiClass *mip = reinterpret_cast<MiClass*>(vp);
Base1 *b1p = reinterpret_cast<Base1*>(vp);
such that static_cast<Base1*>(mip) == b1p;
是否有可以放置在静态断言中的 boost 模板,例如:
is_single_inherited_subclass_of_base<MiClass,SomeBaseInMiClass>()
?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。