std::shared_ptr<T>::get (3) - Linux Manuals
std::shared_ptr<T>::get: std::shared_ptr<T>::get
Command to display std::shared_ptr<T>::get
manual in Linux: $ man 3 std::shared_ptr<T>::get
NAME
std::shared_ptr<T>::get - std::shared_ptr<T>::get
Synopsis
T* get() const noexcept; (until C++17)
element_type* get() const noexcept; (since C++17)
Returns the stored pointer.
Parameters
(none)
Return value
The stored pointer.
Notes
A shared_ptr may share ownership of an object while storing a pointer to another object. get() returns the stored pointer, not the managed pointer.
Example
// Run this code
#include <iostream>
#include <memory>
#include <string_view>
void output(std::string_view msg, int const* pInt)
{
std::cout << msg << *pInt << "\n";
}
int main()
{
int* pInt = new int(42);
std::shared_ptr<int> pShared = std::make_shared<int>(42);
output("Naked pointer ", pInt);
// output("Shared pointer ", pShared); // compiler error
output("Shared pointer with get() ", pShared.get());
delete pInt;
}
Output:
Naked pointer 42
Shared pointer with get() 42
See also
dereferences the stored pointer
operator* (public member function)
operator->
Pages related to std::shared_ptr<T>::get
- std::shared_ptr<T>::operator*,std::shared_ptr<T>::operator-> (3) - std::shared_ptr<T>::operator*,std::shared_ptr<T>::operator->
- std::shared_ptr<T>::operator<< (3) - std::shared_ptr<T>::operator<<
- std::shared_ptr<T>::operator= (3) - std::shared_ptr<T>::operator=
- std::shared_ptr<T>::operator==,!=,<,<=,>,>= (3) - std::shared_ptr<T>::operator==,!=,<,<=,>,>=
- std::shared_ptr<T>::operator[] (3) - std::shared_ptr<T>::operator[]
- std::shared_ptr<T>::operatorbool (3) - std::shared_ptr<T>::operatorbool
- std::shared_ptr<T>::owner_before (3) - std::shared_ptr<T>::owner_before
- std::shared_ptr<T>::reset (3) - std::shared_ptr<T>::reset
- std::shared_ptr<T>::shared_ptr (3) - std::shared_ptr<T>::shared_ptr
- std::shared_ptr<T>::swap (3) - std::shared_ptr<T>::swap
- std::shared_ptr<T>::unique (3) - std::shared_ptr<T>::unique
- std::shared_ptr<T>::use_count (3) - std::shared_ptr<T>::use_count
- std::shared_ptr<T>::~shared_ptr (3) - std::shared_ptr<T>::~shared_ptr
- std::shared_ptr (3) - std::shared_ptr
- std::shared_future (3) - std::shared_future
- std::shared_future<T>::get (3) - std::shared_future<T>::get