I realize this is probably a very easy question for most. However, can anyone tell me how to modify this short piece of code so that the values printed to the screen are both the number 6? What I am trying to achieve here is "real-time" access to the base class for the wtfo class, in the example, the variable anint.
I'm assuming I will have to pass the address of the base class to the wtfo class to do this. Perhaps this is not a good use of base and derived classes?
Simply add w->set_base_anint(6); immediately after line 29.
Remember that public inheritance indicates an is-a relationship: a wtfois abase. In general, a publicly derived class (i.e., a subtype) should be usable anywhere a base-class is expected; this idea is called Liskov substitutability. But clearly you understood this, since you wrote w->get_base_anint() on line 31...
In order to make the is-a relationship efficient, as far as single inheritance is involved, the address of the base class is the address of the derived class.
I want to thank you both (mbozzi and Peter87) for your answers; Peter87, you gave me what I needed there with that. It's nice to have folks provide help without condescension, snide comments or passive aggressive quips. Again, thanks to you both!