It also goes away if you double wrap the inner function call, as so
That was a new input, Thanks.
I'd say it had something to do with order of operation: the compiler doesn't see "ABC b(XYZ());" as creating an ABC named b with parameter XYZ(), but instead creating some kind of bizarre ABC(XYZ*) object, or something: in either case, the additional brackets explicitly tell the order of operation so it does what you expect.
Then why the compiler recognizes the statement ABC b(XYZ(1)), if the constructor is modified to XYZ(int i) ?
Why the compiler treats ABC b(XYZ()) and ABC b(XYZ(1)) differently?
The following are my findings, which are weird.
1. You can see that it doesn't even call XYZ(), by commenting b.print()
2. ABC b(XYZ(1)), by modifying the constructor XYZ(int i), also disappears the error.
3. Modifying the constructor to take ABC b(XYZ(), 1) also doesn't show the error.
4. The only issue is that XYZ() should not be the only argument.
5. I doubt that if the line ABC b(XYZ()) has any similarity with the copy constructor of ABC, which cause the error !!!
In the meantime, don't call constructors like that, use the workaround of explicitly specifying a variable
How ever, the call ABC b(XYZ()) is valid, as it is used to create a temporary object inside a function. If we create a variable outside and pass it, then this particular function will call the copy constructor.