Presentation is loading. Please wait.

Presentation is loading. Please wait.

Inheritance: runtime vs. compile time binding

Similar presentations


Presentation on theme: "Inheritance: runtime vs. compile time binding"— Presentation transcript:

1 Inheritance: runtime vs. compile time binding
Mammal gestate() giveBirth() virtual functions which function is actually called? determined at run-time must call through pointer or reference word “virtual” not needed in derived classes, but good idea for documenting code non-virtual functions are bound at compile-time base classes must have virtual destructor elephant human rabbit void bearYoung(Mammal * m) { m->gestate(); m->giveBirth(); }

2 Trees: solving problems
Store keys, support map aka dictionary operations insert find delete We’ve used arrays/vectors, linked-lists, search trees how find insert delete vector linked list search tree trees used for directories, expressions, games class or struct? template or not?

3 Return a copy of a tree (who clones?)
Tree cloning Return a copy of a tree (who clones?) Tree * clone(Tree * t) { } can a Tree node clone itself? delete itself? issues? what about a mirror copy?

4 Twenty questions (tree applications)
Does it have feathers? No Is it a feline? Yes Is it the king of beasts? No Is it a tiger? No I give up, what animal are you thinking of? cheetah Ask a question that has a “yes” answer for a tiger and a “no” answer for a cheetah: does it have stripes how to store questions? answers? add to knowledge?

5 from one node tree to many node tree
Animal trees Does it fly from one node tree to many node tree different behavior: internal nodes vs. leaves how can tree be saved to a file (to be read later)? Who is responsible for asking questions, printing,... robin robin platypus


Download ppt "Inheritance: runtime vs. compile time binding"

Similar presentations


Ads by Google