c++ - 是否有一种编译时方法来断言基类是“第一个”并且与 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>()
?
解决方案
推荐阅读
- r - 如何绘制因子的每个水平
- python-3.x - 了解“Python 简介”中的 while 循环
- css - 混合图像叠加层和带背景的文本
- java - 将方法的输出传递给java中的另一个方法
- java - java - 使用字符串进行动态转换
- tkinter - tkinter,之后的意外行为,回调
- java - 在 Android 中比较时间?
- c# - 如何使用组合框的存储值到 SQL 连接字符串?
- abaqus - Abaqus:根据 R = f(Th) 定义分析场
- javascript - 如何正确测试使用 axios.get 和 Cheerios.load 函数与 mocha 和 chai 的函数?