首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::shared_ptr::operator->

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>...

二次

代码语言:javascript
复制
#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();
}

二次

产出:

二次

代码语言:javascript
复制
a = 10
a = 10

二次

另见

get

returns the stored pointer (public member function)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com