...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <iostream> struct Widget { explicit Widget(int Ii) { std::cout << "Widget constructed" << std::endl; } }; struct Gadget { explicit Gadget(Widget wid) { std::cout << "Gadget constructed" << std::endl; } }; void f() { int i = 3; Gadget g(Widget(i)); std::cout << i << std::endl; } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <iostream> struct Widget { explicit Widget(int Ii) { std::cout << "Widget constructed" << std::endl; } }; struct Gadget { explicit Gadget(Widget wid) { std::cout << "Gadget constructed" << std::endl; } }; void f() { int i = 3; Gadget g1((Widget(i))); // Use extra parentheses Gadget g2{Widget(i)}; // Use direct initialization std::cout << i << std::endl; } |
...