Skip to content

Instantly share code, notes, and snippets.

@tsaoyu
Created April 3, 2020 13:19
Show Gist options
  • Save tsaoyu/e86a4339c3b52a578adbc729e0a7b210 to your computer and use it in GitHub Desktop.
Save tsaoyu/e86a4339c3b52a578adbc729e0a7b210 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <memory>
class TestClass
{
private:
std::shared_ptr<int> int_shared_ptr;
public:
TestClass()
{
std::cout << "I will create a shared ptr object here.";
std::shared_ptr<int> int_ptr (new int(10));
this -> int_shared_ptr = int_ptr;
std::cout << "The created shared ptr has value of " << *int_shared_ptr << "\n";
}
void check_if_shared()
{
std::cout << "The created shared ptr has value of " << *int_shared_ptr << "\n";
}
};
int main(){
auto tc = TestClass();
tc.check_if_shared();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment