-
Notifications
You must be signed in to change notification settings - Fork 33
/
18.28.txt
32 lines (28 loc) · 913 Bytes
/
18.28.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Exercise 18.28: Given the following class hierarchy, which inherited members
can be accessed without qualification from within the VMI class? Which require
qualification? Explain your reasoning.
struct Base {
void bar(int); // public by default
protected:
int ival;
};
struct Derived1 : virtual public Base {
void bar(char); // public by default
void foo(char);
protected:
char cval;
};
struct Derived2 : virtual public Base {
void foo(int); // public by default
protected:
int ival;
char cval;
};
class VMI : public Derived1, public Derived2 { };
By Faisal Saadatmand
Reguire no qualification:
ival; Derived2::ival overrides Base::ival, and thus, takes precedence over it.
bar; Derived1::bar overrides Base:bar, and thus, takes precedence over it.
Require qualification:
cval; ambiguous--appears in both Derived1 and Derived2
foo; ambiguous--appears in both Derived1 and Derived2