是否有一种编译时方法来断言基类是“第一个”并且在 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 (将#修改为@)