Created
August 16, 2019 09:05
-
-
Save mhamilt/8f508421ac9169aec7b2c0d179951330 to your computer and use it in GitHub Desktop.
Passing a unique pointer to a function
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
#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