Last active
July 11, 2024 17:39
-
-
Save Joshix-1/1597e5d36e3cfed1e41356f5e063272c to your computer and use it in GitHub Desktop.
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 <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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment