std::shared_ptr<T>::operator*, std::shared_ptr<T>::operator->
From cppreference.com
< cpp | memory | shared ptr
C++
Memory management library
|
|
|
std::shared_ptr
Member functions | ||||
Modifiers | ||||
Observers | ||||
shared_ptr::operator*shared_ptr::operator-> | ||||
(C++17)
|
||||
(until C++20*)
|
||||
(C++26)
|
||||
(C++26)
|
||||
Non-member functions | ||||
(until C++20)
(until C++20)
(until C++20)
(until C++20)
(until C++20)
(C++20)
|
||||
functions (until C++26*)
|
||||
Helper classes | ||||
(C++20)
|
||||
Deduction guides(C++17) |
T& operator*
(
)
const
noexcept
;
|
(1) | (since C++11) |
T* operator-
>
(
)
const
noexcept
;
|
(2) | (since C++11) |
Dereferences the stored pointer. The behavior is undefined if the stored pointer is null.
Parameters
(none)
Return value
1) The result of dereferencing the stored pointer, i.e., *get()
2) The stored pointer, i.e., get().
Remarks
When T
is an array type or (possibly cv-qualified)(since C++17)
void
, it is unspecified whether function (1)
std::shared_ptr<void>
When |
(since C++17) |
Example
Run this code
#include <iostream> #include <memory> struct Foo { Foo(int in) : a(in) {} void print() const { std::cout << "a = " << a << '\n'; } int a; }; int main() { auto ptr = std::make_shared<Foo>(10); ptr->print(); (*ptr).print(); }
Output:
a = 10 a = 10
See also
returns the stored pointer (public member function) |