Multiple inheritance and virtual functions

Hello everybody,

I have a strange problem (which could possibly be really simple to solve). I need some help with the background theory of C++. This is my problem:

I have two classes named "Constructor" and "Driver". They both inherit from other (different) classes. Constructor class also includes virtual functions. A third class named "Tester" inherits from both Constructor and Driver. What I need to do is to print the address (absolute value) of my Tester object.

The problem is this:
Lets assume the address of Tester object (called myTester) is X. Casting myTester to Consumer* changes the address to X+8. This casting takes place after calling a function that takes as argument a Constructor*.

Code Example:
-------------

void foo (Constructor* myConstructor) {
cout << myConstructor << endl;
}

Tester *myTester = new Tester();
cout << myTester <<endl; //This prints X
foo (myTester); //This prints X+8

What I need is some reference I can read, or if it's simple and somebody can explain here, about:
(1) Why this happens?
(2) Is the "+8" part constant? Will it ALWAYS add 8?
(3) Would things change on a different machine/architecture?


I know I shouldn't care about the absolute value of an object's address, but I'm writing code to checkpoint a simulator and having the address simplifies things a lot.

Thanks in advance,
Andreas
It probably places Driver data at the beginning of Tester so when you convert from Tester* to Driver* it don't have to do anything because the address is already pointing to the Driver part.

The Constructor data is probably placed after the Driver data so when you convert from Tester* to Constructor* it has to add some fixed amount to the address so that it points to the Constructor part.
Topic archived. No new replies allowed.