Skip to content

Instantly share code, notes, and snippets.

@mhamilt
Created August 16, 2019 09:05
Show Gist options
  • Save mhamilt/8f508421ac9169aec7b2c0d179951330 to your computer and use it in GitHub Desktop.
Save mhamilt/8f508421ac9169aec7b2c0d179951330 to your computer and use it in GitHub Desktop.
Passing a unique pointer to a function
#include <iostream>
#include <memory>
void setPtr (int *a)
{
std::cout << *a << '\n';
}
int main(int argc, const char * argv[])
{
std::unique_ptr<int> x(new int(1));
setPtr(x.get());
std::cout << *x << '\n';
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment