I read in a book that polymorphism is implemented in c++ by three levels of pointers(using vtable) but are there other methods of implementing it in c++ .
Asked
Active
Viewed 1,090 times
4
-
Actually @Mat I was searching for tags with polymorphism that is why i was not able to find the answer you have referred to here. Anywayz thanx . – abkds Jun 02 '13 at 09:45
1 Answers
0
Virtual functions can also be implemented directly with function pointers like this.
struct A
{
void (*foo)(A *thiz);
void (*goo)(A *thiz, int x);
};
But obviously this is less efficient than the normal implementations. And actually C++ implementations may differ a little when dealing with multiply inheritance and virtual base classes.

BlueWanderer
- 2,671
- 2
- 21
- 36
-
@Mat refer the picked answer in [Alternative virtual mechanism implementations](http://stackoverflow.com/questions/4352032/alternative-virtual-mechanism-implementations)?. – BlueWanderer Jun 02 '13 at 08:00
-
@Mat Allow me to start typing the answer before you post the comment. And allow me to believe someone knows vtable can understand my explanation. That's OK. – BlueWanderer Jun 02 '13 at 08:16