Last active
July 11, 2024 17:39
-
-
Save Joshix-1/1597e5d36e3cfed1e41356f5e063272c to your computer and use it in GitHub Desktop.
Revisions
-
Joshix-1 revised this gist
Jul 11, 2024 . 1 changed file with 5 additions and 8 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,24 +1,21 @@ #include <string> #include <iostream> #include <memory> class Foo { public: Foo(char *chars) { std::cout << *(data.get()) << std::endl; data = std::unique_ptr<std::string>(new std::string(chars)); } std::unique_ptr<std::string> data; }; int main() { char str[2] = {42, 0}; Foo foo = {str}; std::cout << "2: " << *(foo.data.get()) << std::endl; } -
Joshix-1 created this gist
Jul 11, 2024 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ #include <string> #include <iostream> class Foo { public: Foo(char *chars) { std::cout << *data << std::endl; data = new std::string(chars); } ~Foo() { delete data; } std::string *data; }; int main() { char str[2] = {42, 0}; Foo foo = {str}; std::cout << "2: " << *(foo.data) << std::endl; }