Created
May 3, 2015 20:04
-
-
Save worenga/ceb54ebee517aad024cb to your computer and use it in GitHub Desktop.
This file contains 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
#include <memory> | |
//cpp11 | |
void consumeFoo(std::unique_ptr<Foo> fooptr) | |
{ | |
//now foo owns fooptr... | |
} | |
int main() { | |
//main transfers owns foo | |
std::unique_ptr<Foo> foo(new Foo); | |
//use make_shared<Foo>(Foo()) in cpp14! | |
//main transfers ownership of foo to consumeFoo... | |
consumeFoo(std::move(foo)); | |
//note that unique ptr has deleted copy ctor | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment