Created
May 25, 2017 13:49
-
-
Save njlr/bbbcbc0ae50c796d8014ac7b0e42ebeb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Widget { | |
Widget() { cout << "Widget created" << endl; } | |
~Widget() { cout << "Widget destroyed" << endl; } | |
}; | |
unique_ptr<Widget> createWindow() { | |
return make_unique<Widget>(); | |
} | |
int main() { | |
auto w = createWindow(); | |
ASSERT(w); | |
// auto w2 = widget; // error: unique_ptr has no copy-constructor | |
auto w3 = move(widget); // w3 owns now the widget, w is empty | |
ASSERT(w3 && !w); | |
// w3 calls destructor of widget; only one object at a time owns the Widget | |
return 0; | |
} |
- auto w3 = move(widget);
+ auto w3 = move(w);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is no variable 'widget'. So line 14 should be 'auto w3 = move(w)', and line 13 should contain 'auto w2 = w ...'