c++ - Is a book shelf branch a branch? -
i building tree structure 3 classes node
, leaf
, branch
.
node
abstract class tree node.leaf
derivednode
cannot have children.branch
derivednode
can have children , have methodadd(node*)
and have concrete class book
leaf
, bookshelf
branch
. however, double if bookshelf
branch
since method add(node*)
not valid when node*
not book. branch
interface not works bookshelf
. how handle things?
the impossibility of modeling collections inheritance 1 of primary motivations inventing templates.
class book { // ... }; typedef std::vector<book> book_shelf;
done.
Comments
Post a Comment