Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Texture {
- Texture(string const& path) { cout << "Texture loaded from " << path << endl; }
- ~Texture() { cout<< "Texture destroyed" << endl; }
- static shared_ptr<Texture> load(string const& path) {
- return make_shared<Texture>(path)
- }
- };
- // this functions will take a copy and increment the counter
- // using const& would not increment the ref-counter
- int doSomethingWithTexture(shared_ptr<Texture> const tex);
- int doSomethingElseWithTexture(shared_ptr<Texture> const tex);
- void foo() {
- shared_ptr<Texture> tex = Texture::load("textures/my_texture.png");
- thread(doSthWithTexture, tex).detach();
- thread(doSthMoreWithTexture, tex).detach();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement