std::shared_ptr<T>:: operator*, std::shared_ptr<T>:: operator->
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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) | (自 C++11 起) |
|
T
*
operator
-
>
(
)
const
noexcept
;
|
(2) | (自 C++11 起) |
解引用存储的指针。若存储的指针为空则行为未定义。
目录 |
参数
(无)
返回值
备注
当
T
是
数组类型或(可能带有 cv 限定符)
(C++17 起)
void
时,函数
(1)
是否被声明是未指定的。如果它被声明,其返回类型也是未指定的,但该函数的声明(尽管不一定是定义)必须是良构的。这使得实例化
std::
shared_ptr
<
void
>
成为可能。
|
当
|
(since C++17) |
示例
#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(); }
输出:
a = 10 a = 10
参见
|
返回存储的指针
(公开成员函数) |