A computer-implemented method for implementing virtual functions for an object-oriented programming language, the programming language having classes, each class defined in terms of base classes and function members, each function member defined as either virtual or non-virtual, each function member when invoked being passed a third pointer, wherein each class that introduces a virtual function member has an associated virtual function table and a virtual function table pointer, the virtual function tables having pointers to the virtual functions defined in the associated class, the method comprising the computer-implemented steps of:
- (a) inputting into the computer system a class definition for a specified class wherein the specified class has a virtual function that overrides a virtual function in at least two base classes, each of such base classes having an associated virtual function table;
- (b) creating a data structure layout for the specified class wherein the data structure layout contains an occurrence of each base class, the occurrences containing a virtual function table pointer for the associated virtual function table, the data structure layout having a class address;
- (c) creating a copy of the virtual function table for each of such base classes;
- (d) compiling the overriding virtual function to expect the this pointer to point to the occurrence in the specified class of a designated base class that is at an offset from the class address;
- (e) overriding the pointer to the virtual function in the virtual function table associated with the designated base class with a pointer to the compiled overriding virtual function;
- and
- (f) for each non-designating base class with the overridden virtual function,
- generating an adjustor to adjust the this pointer and then invoke the compiled overriding function, and
- overriding the pointer to the virtual function in the virtual function table associated with the non-designated class with a pointer to the adjustor.