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

8th Jun 2022, 1:34 PM
Muhammad Talha Atif
Muhammad Talha Atif - avatar
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?
8th Jun 2022, 1:39 PM
Justice
Justice - avatar
+ 1
wait
8th Jun 2022, 1:45 PM
Muhammad Talha Atif
Muhammad Talha Atif - avatar
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 ...
8th Jun 2022, 2:44 PM
Ipang
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.
8th Jun 2022, 2:56 PM
Muhammad Talha Atif
Muhammad Talha Atif - avatar
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.
8th Jun 2022, 9:44 PM
Jan
Jan - avatar
0
Sorry but you cannot add "add_to_base_array" method to Base class?
10th Jun 2022, 12:21 PM
KrOW
KrOW - avatar
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.
10th Jun 2022, 2:54 PM
Jan
Jan - avatar