DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
The Design of C++ Standard Components

Avoiding language features with execution speed penalties

A full discussion of inheritance (and why we have mostly avoided it) can be found at the end of this topic. In that discussion, you will see why our components have very few classes with virtual functions. In the context of the current discussion of execution speed, we can make another case against virtual functions: virtual functions can almost never be inlined. For example, consider the following:

       class T {
       public:
           inline virtual foo() {...}
       };
       void bar(const T& t) {
           t.foo();
       }

The compiler cannot inline the call to foo() in function bar() because there is no way it can determine that the object pointed to by t is of type T (and not some type U derived from T). If T is a class defined in a component, then even though no client ever derives a class from T, yet every client of T must sacrifice the efficiency of inlines.


Next topic: Compilation time
Previous topic: Not checking for client errors

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005