std::weak_ptr::weak_ptr
Aus cppreference.com
<tbody>
</tbody>
constexpr weak_ptr(); |
(1) | (seit C++11) |
weak_ptr( const weak_ptr& r ); |
(2) | (seit C++11) |
template< class Y > weak_ptr( const weak_ptr<Y>& r ); |
(2) | (seit C++11) |
template< class Y > weak_ptr( const std::shared_ptr<Y>& r ); |
(2) | (seit C++11) |
Erzeugt einen neuen weak_ptr, der sich potentiell ein Objekt mit r teilt.
1) Standardkonstruktor. Erzeugt einen leeren weak_ptr .
2) Erzeugt einen neuen weak_ptr , der sich ein Objekt mit r teilt. Wenn r kein Objekt verwaltet, verwaltet *this auch kein Objekt. Die Templates werden nur aktiviert, wenn Y* implizit konvertierbar zu T* ist .
Parameter
{{par | r | Ein std::shared_ptr oder std::weak_ptr, dessen Resource dieser std::weak_ptr übernimmt.
Original:
{{{2}}}
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Ausnahmen
Beispiel
#include <memory>
#include <iostream>
struct Foo {};
int main()
{
std::weak_ptr<Foo> w_ptr;
{
auto ptr = std::make_shared<Foo>();
w_ptr = ptr;
std::cout << "w_ptr.use_count() inside scope: " << w_ptr.use_count() << '\n';
}
std::cout << "w_ptr.use_count() out of scope: " << w_ptr.use_count() << '\n';
}
Output:
w_ptr.use_count() inside scope: 1
w_ptr.use_count() out of scope: 0
Siehe auch
weist einen weak_ptr zu (öffentliche Elementfunktion) | |