C
CoDE++
Every object of Polymorphic class, contains a Virtual pointer ( which
points to Vtable).
If I have 1000 objects of a polymorphic class,
why should i waste 1000*4 bytes for storing the same stuff...
All 1000 object contains the exatly same value of virtual pointer...
so the question is why can't this virtual pointer could have been kept
in class by complier as it keep all the member function definition
somewhere... If a class A has member function func1().. there is only
one copy of it ...for all the objects... then why do we have separate
copy of virtual pointer for each object...while value is same in all
the objects ?
How do you think compiler finds the address of a member function for a
non polymorphic class?
Don't you think the same mechanism could have been used to find out
the virtual pointer for that class also?
points to Vtable).
If I have 1000 objects of a polymorphic class,
why should i waste 1000*4 bytes for storing the same stuff...
All 1000 object contains the exatly same value of virtual pointer...
so the question is why can't this virtual pointer could have been kept
in class by complier as it keep all the member function definition
somewhere... If a class A has member function func1().. there is only
one copy of it ...for all the objects... then why do we have separate
copy of virtual pointer for each object...while value is same in all
the objects ?
How do you think compiler finds the address of a member function for a
non polymorphic class?
Don't you think the same mechanism could have been used to find out
the virtual pointer for that class also?