C++ Inheritance Flashcards

1
Q

In multiple inheritance, in what order are the constructors called?

A

In the same order that they are declared in within the declaration of the calling class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the Diamond Problem?

A

An ambiguous situation caused by multiple inheritance. It occurs when a class inherits from 2 other classes, both of which inherit from a common base class. Thus, when the bottom class tries to access a member of the base class, it does not though which class to inherit the member from.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the names of the 2 potential solutions to the Diamond Problem?

A

Solution 1: Use the scope operator
Solution 2: Use Virtual Inheritance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe how the Scope Operator can resolve the Diamond Problem…

A

The derived instance can specify through which class is wants to inherit the base class member.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe how Virtual Inheritance can resolve the Diamond Problem…

A

Prevents multiple copies of the Common Base Class being copied to the Derived Class. Thus, only 1 copy of the base class is shared with the derived classes. This removes ambiguity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How does Virtual Inheritance work?

A

When multiple classes virtually inherit a common base class, only 1 copy of the common base class is inherited across all the derived classes. Thus there is no ambiguity when a derived class attempts to access a member of the base class, since all derived classes have the same copy.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the umbrella term of Virtual Members consist of?

A

Virtual Classes + Virtual Functions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What causes ambiguity in inheritance?

A

When a class derives multiple classes, each of which have their own assignment of a variable of the same name. Thus, when the derived class calls the variable, it doesn’t know from which class to call the variable from.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Provide an implementation of the Diamond Problem. Then resolve it using Virtual Inheritance…

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly