In this code:
void Window::oops() { printf("Window oops\n"); }
void TextWindow::oops() {
printf("TextWindow oops %d\n", cursorLocation);
}
TextWindow x;
Window a;
Window *b;
TextWindow *c;
a = x; a.oops(); // executes Window version
b = &x; b->oops(); // executes TextWindow or Window version
c = &x; c->oops(); // executes TextWindow version
What does it mean that b = &x; b->oops(); will execute the TextWindow or Window version? How is it decided?
If
oops()is virtual, theb->oops()call will use theTextWindowversion. If it is not, it will use theWindowversion.