c++ - Is a book shelf branch a branch? -


i building tree structure 3 classes node, leaf , branch.

  1. node abstract class tree node.
  2. leaf derived node cannot have children.
  3. branch derived node can have children , have method add(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

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -