[ Web Proxy ]
URL:
Viewing: https://fr.cppreference.com/cpp/memory/weak_ptr [Back]  [Original]

std::weak_ptr cppreference.com
cppreference.com
Espaces de noms
Variantes

std::weak_ptr

De cppreference.com


 
 
 
La gestion dynamique de la mmoire
Faible niveau de gestion de la mmoire
Rpartiteurs
Original:
Allocators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
allocator
allocator_traits (C++11)
allocator_arg_t (C++11)
allocator_arg (C++11)
uses_allocator (C++11)
scoped_allocator_adaptor (C++11)
Non initialise stockage
Original:
Uninitialized storage
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
uninitialized_copy
uninitialized_copy_n (C++11)
uninitialized_fill
uninitialized_fill_n
raw_storage_iterator
get_temporary_buffer
return_temporary_buffer
Pointeurs intelligents
Original:
Smart pointers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
unique_ptr (C++11)
shared_ptr (C++11)
weak_ptr (C++11)
auto_ptr (obsolte)
owner_less (C++11)
enable_shared_from_this (C++11)
bad_weak_ptr (C++11)
default_delete (C++11)
Soutien garbage collection
Original:
Garbage collection support
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
declare_reachable (C++11)
undeclare_reachable (C++11)
declare_no_pointers (C++11)
undeclare_no_pointers (C++11)
pointer_safety (C++11)
get_pointer_safety (C++11)
Divers
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
pointer_traits (C++11)
addressof (C++11)
align (C++11)
Bibliothque C
Original:
C Library
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
std::weak_ptr
Les fonctions membres
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
weak_ptr::weak_ptr
weak_ptr::~weak_ptr
weak_ptr::operator=
Modificateurs
Original:
Modifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
weak_ptr::reset
weak_ptr::swap
Des observateurs
Original:
Observers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
weak_ptr::use_count
weak_ptr::expired
weak_ptr::lock
weak_ptr::owner_before
Tiers fonctions
Original:
Non-member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
std::swap
 
<tbody> </tbody>
Dclar dans l'en-tte <memory>
template< class T > class weak_ptr;
(depuis C++11)
std::weak_ptr est un pointeur intelligent qui dtient une rfrence non-propritaire (faible) un objet qui est gr par std::shared_ptr. Il doit tre converti en std::shared_ptr afin d'accder l'objet rfrenc.
Original:
std::weak_ptr is a smart pointer that holds a non-owning ("weak") reference to an object that is managed by std::shared_ptr. It must be converted to std::shared_ptr in order to access the referenced object.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

std::weak_ptr modlise une proprit temporaire: quand un objet doit tre accessible uniquement si il existe, et il peut tre supprim tout moment par quelqu'un d'autre, std::weak_ptr est utilis pour suivre l'objet, et il est converti en std::shared_ptr d'assumer la proprit temporaire. Si le std::shared_ptr original est dtruit ce moment, la dure de vie de l'objet est prorog jusqu'au premier std::shared_ptr temporaire est dtruite ainsi .

En outre, std::weak_ptr est utilise pour briser les rfrences circulaires de std::shared_ptr .
Original:
In addition, std::weak_ptr is used to break circular references of std::shared_ptr.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Types de membres

Type du membre Dfinition
element_type T

Fonctions membres

cre un nouveau weak_ptr
Original:
creates a new weak_ptr
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique) [edit]
dtruit un weak_ptr
Original:
destroys a weak_ptr
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique) [edit]
assigne la weak_ptr
Original:
assigns the weak_ptr
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique) [edit]
Modificateurs
Original:
Modifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
libre la proprit de l'objet gr
Original:
releases the ownership of the managed object
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique) [edit]
permute les objets grs
Original:
swaps the managed objects
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique) [edit]
Des observateurs
Original:
Observers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
retourne le nombre d'objets qui grent shared_ptr l'objet
Original:
returns the number of shared_ptr objects that manage the object
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique) [edit]
vrifie si l'objet rfrenc a dj t supprim
Original:
checks whether the referenced object was already deleted
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique) [edit]
cre un shared_ptr qui gre l'objet rfrenc
Original:
creates a shared_ptr that manages the referenced object
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique) [edit]
fournit propritaire base ordre des pointeurs faibles
Original:
provides owner-based ordering of weak pointers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique) [edit]

Fonctions annexes

l'algorithme spcialis std::swap
Original:
specializes the std::swap algorithm
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction gnrique) [edit]

Exemple

Montre comment verrou est utilis pour assurer la validit du pointeur .
Original:
Demonstrates how lock is used to ensure validity of the pointer.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <iostream>
#include <memory>

std::weak_ptr<int> gw;

void f()
{
    if (auto spt = gw.lock()) { // Has to be copied into a shared_ptr before usage
	std::cout << *spt << "\n";
    }
    else {
        std::cout << "gw is expired\n";
    }
}
 
int main()
{
    {
        auto sp = std::make_shared<int>(42);
	gw = sp;

	f();
    }

    f();
}

Rsultat :

42
gw is expired

Web Proxy Viewer  |  New URL  |  Original Page