Puzzle 5 | A Destructive Relationship |
| #include <iostream> |
| #include <memory> |
| |
| struct Widget |
| { |
| virtual void draw() { std::cout << "Widget draw\n"; } |
| virtual ~Widget() { std::cout << "Widget destructor\n"; } |
| }; |
| |
| struct Button : public Widget |
| { |
| void draw() override { std::cout << "Button draw\n"; } |
| ~Button() override { std::cout << "Button destructor\n"; } |
| }; |
| |
| int main() |
| { |
| std::unique_ptr<Widget> widget = std::make_unique<Button>(); |
| widget->draw(); |
| } |
Guess the Output | |
---|---|
Try to guess what the output is before moving to the next page. |
The program displays ...
Get C++ Brain Teasers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.