How are vtables implemented in c++ and c#?

Lets have this situation (in c++, in c# classes A,B are interfaces):

class A { virtual void func() = 0; };
class B { virtual void func() = 0; };
class X: public A, public B { virtual void func(){ var = 1; } int var;};

X * x = new X; // from what I know, x have 2 vtables, is this the same in c#?
A * a = (A*)x; // a == x
B * b = (B*)x; // here b != x, so when calling b->func(), how is the address of var correct?

Does the c# compiler create always one vtable? Does it make any pointer fixups when casting?

5
задан chris 3 September 2010 в 10:07
поделиться