0

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.

curiousguy
  • 8,038
  • 2
  • 40
  • 58
Panakotta00
  • 135
  • 9
  • 2
    You'll need to specify what environment you're working in (OS & compiler), this is not specified in standard C++ – Mat Oct 24 '19 at 09:47
  • 1
    Why is the order important to you? – HolyBlackCat Oct 24 '19 at 09:47
  • 2
    ***Why?*** What is the problem you have that rearranging the data like that will solve? – Some programmer dude Oct 24 '19 at 09:47
  • 1
    Please tell us what are you trying to achieve. I don't believe that there is a portable solution to this. – g_bor Oct 24 '19 at 09:47
  • 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 B data at the front. – Panakotta00 Oct 24 '19 at 09:50
  • Why do you write "vtable"? Instance don't have a vtable in them. – curiousguy Oct 27 '19 at 00:44
  • "_which uses for all classes void* pointers to "fake" the vtables... now I use that code base and inherit it,_" It would help if you could show the relevant part of that code and explain the exact assumptions that are made here. – curiousguy Oct 27 '19 at 00:45

0 Answers0