Is the Vtable is same for multiple instances of a particular class.

Is the Vtable is same for multiple instances of a particular class.
Suppose i am having a class

class Base
{
   public:
       virtual void Sample();
       virtual void Print();
};
class Derived : public Base
{
    public:
        void Sample();//overriding the base class virtual function.
};
void main()
{
    Base* b1 = new Derived;
    b1->Sample();//it will call the derived class function.
    Base* b2 = new Base;
    b2->Sample();//it will call the Base class function.
}

my question is Is the Vtable is same for b1 and b2.
jabaroothAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KangaRooCommented:
Actually the C++ standard doesn't specify how the compiler should implement virtual functions. It doesn't talk abot VTables either.
However one might assume that b1 and b2 have different VTables, since they are of different (though related) classes. One could assume that two objects of one class share the same VTable.
But that are all assumptions.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nietodCommented:
Like kangaroo said, there is no gaurantee, but usually all objects of the same class will share the same vtable.  However objects of different classes might also share the same vtable too (like if a derived class redefines no virtual functions it could use the same vtable as its base class (However typical implimentations of RTTI now make that optimization unusable)).  
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.