A question regarding inheritance implementation. Let's say we have 2 classes:
class B
{
public:
int x; // for the sake of argument it's public, don't stone me
};
class D: public B
{
public:
int x; // again x, i know ... stupid dilemma
};
Now, if you will use a sizeof on the newly created type D you'll see it has a size of 8 bytes that means that the created D class has 2 x members which means in my opinion that the class looks something like that:
class D
{
public:
int x;
int x; // problem !!!
}
Now for member functions this ain't a problem, i know that they are not part of the object and the this pointer solves the problem regarding who to call(taking in account the vtable), but what about the member variables? How does the compiler implement behind the curtain the derived D class in such a way that there's no conflict of names.
Is the member variable from the base class renamed? I know that in C++ you can simply call B::x and the compliler knows what you mean but how would this be implemented in C let's say ...? How would the class D as struct look ?
To make it short , how is actually INHERITANCE IMPLEMENTED?
P.S. I know it's compiler stuff and compiler dependent but my guess is that all compilers somehow go the same way so it's a pretty general question and ... it simply interests me.
Thx for all reply's