Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "boost/date_time.hpp"
- #include <iostream>
- #include <string>
- #include <thread>
- namespace
- {
- class Example
- {
- public: // interface
- Example() : test_(new int(7)){}
- ~Example()
- {
- std::cout << "~Example" << std::endl;
- delete test_;
- test_ = nullptr;
- }
- void explode()
- {
- std::cout << "TEST: " << *test_ << std::endl;
- }
- private: // data
- int* test_;
- }; // class
- void printVal(Example& val)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(5000));
- std::cout << "Accessing reference to shared_ptr owned object" << std::endl;
- val.explode();
- }
- } // namespace
- int main(int argc, char** argv)
- {
- auto sharedInt = std::make_shared<Example>();
- std::thread printThread(&printVal, std::ref(*sharedInt) );
- sharedInt.reset();
- std::this_thread::sleep_for(std::chrono::milliseconds(10000));
- } // main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement