C++ Interview Report
- 0of 0 votes
AnswersEvery object of Polymorphic class, contains a Virtual pointer ( which points to Vtable).
- Crime_Master_GoGo August 03, 2010
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?| Report Duplicate | Flag | PURGE
C++ - 0of 0 votes
AnswersI was asked what is the size of an empty C++ class.
class A { // No member variable inside // no member function ( doesn't make //difference anyways) }
I answer that it's One byte.. then i was asked immediately why?
- Crime_Master_GoGo August 03, 2010| Report Duplicate | Flag | PURGE
C++