0
I want to see 34 in derived 2 class function too. I wanna see how can I get same answer by making changes through derived 1.
Code is here https://code.sololearn.com/czm7Ks5G51db/?ref=app
7 Answers
+ 2
This is a really long wall of text. Can you please put this in a Code Bit and then share the link in the body of your question?
+ 1
wait
0
What if class Derived2 is set to extend class Derived1? that way class Derived2 inherits add_to_base_array() from class Derived1, and display() from class Base.
Sorry if I misunderstood the point ...
0
Dude there will be ambiguity if I inherit base and derived 1 in derived 2..I have tried it...Kindly tell me any possible way to print same answer for Derived 2 if there are changes made by derived 1 to base 1.
0
I think the problem is that you are creating two different objects. The second object is a new copy of the class. The change you made in the Derived1 class, doesn't exist in the new object you are creating from Derived2.
0
Sorry but you cannot add "add_to_base_array" method to Base class?
0
There is an easy solution if Derived2 inherits from Derived1, but since you want an abstract solution, you need to read the lessons about virtual functions and abstract classes.