+ 1
Why 14 is not printing? ..How to call base class parameterized constructor in derived class copy constructor in C++?
6 Antworten
+ 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.
+ 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?
+ 1
Shadow Solution how to print it?
+ 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
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?