1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
In section ref(VIRTCONS) the notion of virtual constructors was introduced. In
that section a class tt(Base) was defined as an abstract base class. A class
tt(Clonable) was defined to manage tt(Base) class pointers in containers like
vectors.
As the class tt(Base) is a minute class, hardly requiring any implementation,
it can very well be defined as a nested class in tt(Clonable). This
emphasizes the close relationship between tt(Clonable) and
tt(Base). Nesting tt(Base) under tt(Clonable) changes
verb( class Derived: public Base)
into:
verb( class Derived: public Clonable::Base)
Apart from defining tt(Base) as a nested class and deriving from
tt(Clonable::Base) rather than from tt(Base) (and providing tt(Base) members
with the proper tt(Clonable::) prefix to complete their fully qualified
names), no further modifications are required. Here are the modified parts of
the program shown earlier (cf. section ref(VIRTCONS)), now using tt(Base)
nested under tt(Clonable):
verbinclude(-a examples/virtcons)
|