Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save worenga/ceb54ebee517aad024cb to your computer and use it in GitHub Desktop.
Save worenga/ceb54ebee517aad024cb to your computer and use it in GitHub Desktop.
#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