I came across the following practice question and answer while studying C++ and I do not understand it.
Given:
class B {};
struct A {
A( B b );
};
Call the function void test( A a, int* b=0);
with the two corresponding variables B b, int i;
The answer is test( b, &i );
My question is, how is it enough to pass the necessary parameter of the constructor and not actually call it? In my mind, the answer should have been:
test( A(b), &i);
Copyright Notice:Content Author:「IntegrateThis」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/39864867/constructors-for-structs-in-c