Polymorphism, virtual

Hi, I've got two classes: One and Two. Class One is base class for Two. Both classes have "Run" function. When I write in main function something like this:

One a;
cout<<sizeof(a);

it gives "1". When I make write "virtual" before function "Run" in base class, and debug the program it gives "3". Why this results are different?
In the second case, the compiler generates a data member for the class, which contains the address of the Run-method to call. This is used to realize polymorphism.
More accurately the compiler adds a pointer to the virtual method table.
If you added a second virtual method to the class its size would still
probably be 3.
Topic archived. No new replies allowed.