Questions tagged [weak-ptr]

std::weak_ptr is a smart pointer that holds a non-owning ("weak") reference to an object that is managed by std::shared_ptr

The std::weak_ptr is a smart pointer that holds a non-owning ("weak") reference to an object that is managed by std::shared_ptr.

The class template std::weak_ptr is designed for use with and represents a non-owning reference; useful in avoiding circular references, it can also be used as a "tracking reference" and converted to a std::shared_ptr when ownership is required.

261 questions
-1
votes
2 answers

about race condition of weak_ptr

1. i posted the question(About thread-safety of weak_ptr) several days ago,and I have the other related question now. If i do something like this,will introduce a race condition as g_w in above example ?(my platform is ms vs2013) std::weak_ptr
Leonhart Squall
  • 810
  • 1
  • 7
  • 15
-2
votes
1 answer

How to not allow conversion from temporary shared_ptr to weak_ptr for derived types

I have asked this question for concrete types. The provided solution is sufficient for those, but when it comes to inheritance, it fails. Would there be a solution to that as well? Lets have a inheritance of classes Foo and IFoo such that class Foo:…
Croolman
  • 1,103
  • 13
  • 40
-2
votes
2 answers

Possible to create weak_ptr to set elements

I have a std::multiset of objects (created in place with set::emplace). This gives me sorted access using a custom comparator. The objects themselves also contain a list of pointers to other objects that identify some dependencies (the dependencies…
sheridp
  • 1,386
  • 1
  • 11
  • 24
-4
votes
1 answer

Can I memcpy std::weak_ptr?

First off, what is the typical implementation of a std::weak_ptr? Particularly is std::weak_ptr just a pointer to the control block of a std::shared_ptr? If all the std::shared_ptr references are gone is the internal control block deleted? If so,…
Game_Overture
  • 1,578
  • 3
  • 22
  • 34
-4
votes
3 answers

Why destructor isn't invoked?

#include #include struct Foo { Foo() { std::cout << "Constructor ...\n"; } void doSth() {std::cout << "hi" << std::endl;} ~Foo() { std::cout << "Destructor ...\n"; } }; int main() { {std::weak_ptr jack =…
Vito
  • 23
  • 2
1 2 3
17
18