[Solved] Please explain output from the `function1(p1,p2,p3);`


point(const coordinate &cpy) is not a copy constructor. You haven’t provided a copy constructor for point. When function1 is called p2 and p3 will be constructed from the compiler generated default copy constructor. This will call the default copy constructor for coordinate to copy the xy member. This why you get two CPY C coordinate output lines. (Incidentally, the ref member of the newly constructed point will refer to the xy member of the source object, not the one in the newly constructed object.)

If you call function1(p1,p2.xy,p3.xy); then you’d see the cpy C point you’re expecting, as the parameter points will be constructed from the coordinates of p2 and p3.

solved Please explain output from the `function1(p1,p2,p3);`