19) If a hierarchy contains a layer (or single class) which has no data, but pro
ID: 3836746 • Letter: 1
Question
19) If a hierarchy contains a layer (or single class) which has no data, but provides an abstract API for its children to follow — and may therefore serve to clarify the tree to programmers using these classes — is this okay?
If you do this, what members must be in the class for the hierarchy to compile and run correctly?
22) Multiple inheritance is seldom used. It is one of the C++ features that Java has removed, in fact. Give a specific example of when you could use multiple inheritance.
Now explain how to code your example without multiple inheritance.
) Why is multiple inheritance such a troublesome feature of C++? Give a ’specific’ example of what can go wrong.
Is there any way to resolve this trouble within the inheritance system? (That is, still use multiple inheritance, but not have the trouble arise..?)
24) If we were to use protected or private instead of public for the mode of inheritance, what changes does this cause later in the hierarchy?
Within the following table, the cell values indicate the member accessibility with respect to the child class which inherits via the column heading inheritance mode a data member which has access mode (in the parent) given by the row heading.
25) Explainhowonecanusethedynamiccastlanguagefeaturetodeterminewhattypeofobjectabase-classpointeractually points to.
26) The standard library also includes the typeinfo library. What struct/class in this library can be used to determine exact type names at run-time? What function(s) in this library help(s) with this task?
Explain how you could use the facilities of the typeinfo library to determine what type of object a base-class pointer actually points to.
27) Which of these two methodologies (dynamic cast or the typeinfo library) seems best? Why?
28) If a class has a static data member, this single memory location will be shared by all objects instantiated of the class. What if some class chooses the class with the static member as its parent — objects of the child class will .
A) get their own memory location to share
B) share the same memory location as did all their parent class’ objects
C) go out for tea on Saturday afternoons
D) inherit a non-static version of the data member — static only applies the first time it is used E) not inherit the static data member — this is an exception to data members being inherited
29) Within the following table, place a check mark in each cell to indicate that the row class can inherit from the column class. (I’ve filled in the first box for you. *smile*) (Hint: There is some duplication in the entries. Of course this could work for you or against you. *shrug*)
Parent<row> -->
Child <column>:
non-template
template pattern
template pattern
non-template
template pattern
template pattern
Parent<row> -->
Child <column>:
non-template
template pattern
template pattern
non-template
template pattern
template pattern
Explanation / Answer
19)
Yes this is possible. Here we can call the class which is providing the abstract API to the other classes as abstract base class. Then the derived classes must provide the implementation for the abstract base methods or functions contained in base class.
In order to compile and execute the code correctly we must provide the code for abstract methods or functions in the base class correctly by overriding the base class methods or functions.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.