Last active
January 19, 2023 18:08
-
-
Save Aposhian/7e6f2ac86ae2cc025fb3e334c13b243e to your computer and use it in GitHub Desktop.
Moving local into shared_ptr
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> | |
#include <iostream> | |
#include <vector> | |
struct Obj { | |
std::vector<int> data; | |
}; | |
int main() { | |
std::shared_ptr<Obj> local_shared; | |
{ | |
Obj local{{1 ,2, 3}}; | |
local_shared = std::make_shared<Obj>(std::move(local)); | |
} | |
std::cout << local_shared->data[0] << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment