std::shared_ptr::operators
STD::共享[医]PTR::操作员%2A、性病::共享[医]PTR::操作员->
T& operator*() const; | (1) | (since C++11) |
---|---|---|
T* operator->() const; | (2) | (since C++11) |
解析存储的指针。如果存储的指针为NULL,则行为未定义。
参数
%280%29
返回值
1%29取消引用存储指针的结果,即,*get()
2%29存储的指针,即,get()
例外
noexcept
规格:
noexcept
评语
何时T
是%28可能是cv-合格%29void
,未指定函数%281%29是否声明。
When T is an array type, it is unspecified whether these member functions are declared, and if they are, what their return type is, except that the declaration (not necessarily the definition) of these functions is well-formed. | (since C++17) |
---|
如果在未指定的情况下声明了任何一个函数,则未指定其返回类型,但声明%28(虽然不一定是函数的定义%29)保证是合法的。这使得实例化成为可能。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(
}
二次
产出:
二次
a = 10
a = 10
二次
另见
get | returns the stored pointer (public member function) |
---|
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
http://en.cppreference.com/w/cpp/Memory/Shared[医]PTR/算子[医]星[医]