+ 1

Why 14 is not printing? ..How to call base class parameterized constructor in derived class copy constructor in C++?

https://code.sololearn.com/cqDLqInQfUAC/?ref=app

11th Aug 2022, 12:58 PM
Muhammad Talha Atif
Muhammad Talha Atif - avatar
6 ответов
+ 2
14 is not printing because after setting `a` to the value of `x` via the base class constructor in line 16, you go ahead and immediately overwrite it with the value of `a` in the copied object in line 17.
11th Aug 2022, 1:13 PM
Shadow
Shadow - avatar
+ 2
Depends on what you want. Your copy constructor is a bit unusual, so I'm not sure what exactly your goal is. What output do you would like to have in the code you just posted?
11th Aug 2022, 1:32 PM
Shadow
Shadow - avatar
+ 1
Shadow Solution how to print it?
11th Aug 2022, 1:21 PM
Muhammad Talha Atif
Muhammad Talha Atif - avatar
11th Aug 2022, 1:26 PM
Muhammad Talha Atif
Muhammad Talha Atif - avatar
+ 1
Ah, I see. Well, your way of calling the constructor is definitely correct, it's just that you overwrote the value again. I guess this is what a "standard" implementation would look like: https://code.sololearn.com/cCv6GcdD5Pp8/?ref=app
11th Aug 2022, 1:45 PM
Shadow
Shadow - avatar
0
I want to just check that parameterized constr.. works in derived copy constr....Do you have any way to implement it other than my recent posted code?
11th Aug 2022, 1:35 PM
Muhammad Talha Atif
Muhammad Talha Atif - avatar