Aussie AI
Initializer lists for base objects
-
Book Excerpt from "Generative AI in C++"
-
by David Spuler, Ph.D.
Initializer lists for base objects
Base objects. Similar efficiency considerations apply to constructors in derived classes, since the data member(s) in the base class act like an object member. The constructor for the base class is always called when a derived class object is constructed. When the default constructor for the base class is of no use to a derived class object, it is more efficient to pass arguments directly to a non-default base class constructor, using the special initialization syntax. The same syntax applies as for data member initialization, except that the type name of the base class is used instead of the name of a data member. A contrived example of this form of initialization is:
class Derived : public Base { public: Derived() : Base(0) { } // Call Base(int) constructor };
• Next: • Up: Table of Contents |
The new AI programming book by Aussie AI co-founders:
Get your copy from Amazon: Generative AI in C++ |