-
Notifications
You must be signed in to change notification settings - Fork 33
/
15.14.txt
23 lines (19 loc) · 1001 Bytes
/
15.14.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Exercise 15.14: Given the classes from the previous exercise and the following
objects, determine which function is called at run time:
base bobj; base *bp1 = &bobj; base &br1 = bobj;
derived dobj; base *bp2 = &dobj; base &br2 = dobj;
(a) bobj.print(); (b) dobj.print(); (c) bp1->name();
(d) bp2->name(); (e) br1.print(); (f) br2.print();
By Faisal Saadatmand
Technically, all the calls to the print member are in error, for they are
missing the ostream& argument. Ignoring this fact, a virtual function called
through a reference or a pointer, the choice of which function to execute is
resolved (at runt time) according the dynamic type of the passed argument.
Note that all member functions have an additional implicit parameter that is
always passed as argument "by pointer", the this pointer.
(a) base print
(b) derived print: implicit this passed by pointer
(c) base name
(d) base name: name is not a virtual function
(e) base print
(f) derived print: implicit this passed by pointer