c++ - Is a book shelf branch a branch? -
i building tree structure 3 classes node, leaf , branch.
nodeabstract class tree node.leafderivednodecannot have children.branchderivednodecan 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