+ 1
Parametric constructor with istream object
Hi Refer code below. It works okay with default constructor. If I remove that one, obviously it will throw error. Can I make this work without default constructor? In other words, can I have parametric constructor works without default constructor? https://sololearn.com/compiler-playground/cqmGZ1z3VC6e/?ref=app
7 ответов
+ 2
It is requiring the default constructor because you are creating an object without parameters. obj2. If you only want to use the parametric constructor, then you must include the constructor parameters to instantiate the object.
That's my best understanding of your code after a quick review.
+ 2
have you tried providing default values to the constructor parameters?
currency(int r=0, int p=0):rs(r),paise(p){}
This is what your default constructor is essentially doing anyway.
if you don't really private properties, structs are simpler because you don't need friend priviledge for ostream
https://sololearn.com/compiler-playground/c07GI4labF8p/?ref=app