3. This one is just a nuisance, really: When the console program runs, I get "class Menu - Inside of 'Menu' default constructor" displayed TWICE. Why does it appear twice when the Menu constructor (and derived class constructor) is defined only once within menu.cpp?
|
Lines 10 and 13 of Main.cpp create two different Menu objects. The code on line 10 will call the Menu constructor, which I'm sure you know already. In addition, although the 'class2' object is of type Derived, it inherits from type Menu, and thus will execute the Menu constructor too (before the Derived constructor). This explains the two identical lines in your output.
With respect to your first two questions, I'm not getting the same behaviour. I ran your code above and got the following output:
class Menu - Inside of 'Menu' default constructor
class Menu - Inside of 'Menu' default constructor
class Derived - Inside the 'Derived' constructor
class Menu showTitle() H-A-N-G-M-A-N
CLASS DERIVED (overridden)Menu: showMenu()
******************************************
<---- Menu under construction at this time---->
class Menu showSelection() - Please enter your selection:
A.
B.
C.
class Menu - getSelection() - return the user's selectionA
Inside the Class Derived showHiScore()
The High Score is: 1000
|
(Note that I put in 'A' as an input to the program above)
So, I was able to get the high score shown, and the getSelection() output worked as expected. This answers your questions 1 and 2.
If you're not getting this behaviour, perhaps tell us some more about the environment and compiler you're using.
Hope that helps.
P.S. You have a variable 'sel' in your Menu.h, and also a local variable 'sel' in your main method. This doesn't look good to me! Think about the problems that this can cause, and try to fix it.