Reputation: 11651
I came across this question and wanted to know what the answer would be ?
Which of the following options describe the expected overhead of class that has five virtual functions ?
A. Every object of the class holds the address of a structure holding the address of the 5 virtual functions
B. Every object of the class holds the address of the five virtual functions
C. Every object of the class holds the address of the next virtual function.
D.Every object of the class holds the address of the link list object that holds the address of the virtual functions.
E.Every object of the class holds the address of the class declaration in memory through which virtual function calls are resolved.
I am familiar with the virtual tables , that each class has a virtual table that indicates which virtual function points to which implementation . However i am not sure how instances of classes communicate with that virtual table. My guess would be A. Please let me know if I am right/wrong and also some explanation to the answer .
Upvotes: 2
Views: 938
Reputation: 333
I think officially the standard does not specify how the V-table is implemented, but i would also say its answer A.
http://en.wikipedia.org/wiki/Virtual_method_table
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf
Section 10.3 doesn't specify any specific implementation.
From section 10.3 "The virtual specifier implies membership, so a virtual function cannot be a nonmember (7.1.2) function. Nor can a virtual function be a static member, since a virtual function call relies on a specific object for determining which function to invoke"
No more than that.
Upvotes: 4