Force a specific arrangement of virtual and non virtual base classes

73 views Asked by At

If I have a code like this:

class A {
public:
    int data1;
}

class B {
public:
    virtual void test() {}
}

class C : public A, public B {
    int data2;
}

and when I now create an instance of C its memory layout looks something like this:

B::vtable
A::data1
C::data2

but what I actually want is something like this:

A::data1
B::vtable
C::data2

Is there some kind of keyword to force the inheritance order?

Is use VC++15 to compile, and what the problem is that I use a big autogenerated code base which uses for all classes void* pointers to "fake" the vtables... now I use that code base and inherit it, this instances now need a special order of memory layouts to work correctly with a different framework to load. And that framework needs the A data at the front.

0

There are 0 answers