In the book "Effective C ++", paragraph 27
class Widget { public: explicit Widget(int size); ... }; void doSomeWork(const Widget& w); doSomeWork(Widget(15)); // create Widget from int // with function-style cast
I'm not sure exactly what happens when doSomeWork is called. I think the w parameter of the doSomeWork function is initialized by another Widget using the copy constructor, but where is the other Widget? Is this a temporary object created by casting as indicated in the comments? Can someone tell me in detail what was caused when the doSomeWork function parameter was initialized?
The wfunction parameter doSomeWorkis the one Widgetyou created as the parameter in the line
w
doSomeWork
Widget
doSomeWork(Widget(15));
doSomeWork a Widget, . , , , doSomeWork(const Widget &w) pass .
doSomeWork(const Widget &w)
, , , .