inheritance runtime vs compile time binding l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Inheritance: runtime vs. compile time binding PowerPoint Presentation
Download Presentation
Inheritance: runtime vs. compile time binding

Loading in 2 Seconds...

play fullscreen
1 / 5

Inheritance: runtime vs. compile time binding - PowerPoint PPT Presentation


  • 169 Views
  • Uploaded on

Mammal. gestate() giveBirth(). human. elephant. rabbit. Inheritance: runtime vs. compile time binding. virtual functions which function is actually called? determined at run-time must call through pointer or reference

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Inheritance: runtime vs. compile time binding' - Jimmy


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
inheritance runtime vs compile time binding

Mammal

gestate()

giveBirth()

human

elephant

rabbit

Inheritance: runtime vs. compile time binding
  • 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

void bearYoung(Mammal * m)

{

m->gestate();

m->giveBirth();

}

trees solving problems
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?
tree cloning
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?
twenty questions tree applications
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?
animal trees

Does it fly

platypus

robin

robin

Animal trees
  • 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,...