T& operator*() const; | (1) | (since C++11) |
T* operator->() const; | (2) | (since C++11) |
Dereferences the stored pointer. The behavior is undefined if the stored pointer is null.
(none).
*get()
get()
noexcept
specification: noexcept
When T
is a (possibly cv-qualified) void
, it is unspecified whether function (1) is declared.
When | (since C++17) |
If either function is declared despite being unspecified, it is unspecified what its return type is, except that the declaration (although not necessarily the definition) of the function is guaranteed to be legal. This makes it possible to instantiate std::shared_ptr<void>
.
#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
returns the stored pointer (public member function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/memory/shared_ptr/operator*