std::shared_ptr::use_count
Da cppreference.com
< cpp | memory | shared ptr
![]() | This page has been machine-translated from the English version of the wiki using Google Translate. The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
long use_count()const; | ||
Returns the number of different shared_ptr
instances (this included) managing the current object. If there is no managed object, 0 is returned.
Índice |
[editar]Parâmetros
(Nenhum)
Original:
(none)
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.
[editar]Valor de retorno
the number of shared_ptr
instances managing the current object or 0 if there is no managed object.
[editar]Exemplo
#include <memory> #include <iostream> void fun(std::shared_ptr<int> sp){std::cout<<"fun: sp.use_count() == "<< sp.use_count()<<std::endl;} int main(){std::shared_ptr<int> sp1 {std::make_shared<int>(5)};std::cout<<"sp1.use_count() == "<< sp1.use_count()<<std::endl; fun(sp1);}
Saída:
sp1.use_count() == 1 fun: sp.use_count() == 2
[editar]Veja também
Verifica se o objeto gerenciado é gerido apenas pela instância shared_ptr atual Original: checks whether the managed object is managed only by the current shared_ptr instance The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função pública membro) |