shared_ptr::operator->

获取一个指向该指定的值。

Ty *operator->() const;

备注

选择运算符返回 get(),因此,该表达式 sp->member 行为与 sp 是选件类 shared_ptr<Ty>对象的 (sp.get())->member 相同。 因此,存储的指针不能为 null,因此,Ty 必须是选件类、结构或联合类型与成员 member。

示例

 

// std_tr1__memory__shared_ptr_operator_ar.cpp 
// compile with: /EHsc 
#include <memory> 
#include <iostream> 
 
typedef std::pair<int, int> Mypair; 
int main() 
    { 
    std::shared_ptr<Mypair> sp0(new Mypair(1, 2)); 
 
    std::cout << "sp0->first == " << sp0->first << std::endl; 
    std::cout << "sp0->second == " << sp0->second << std::endl; 
 
    return (0); 
    } 
 
  

要求

标头: <memory>

命名空间: std

请参见

参考

shared_ptr Class

shared_ptr::get

shared_ptr::operator*