Namespaces
Variants

std::shared_ptr<T>:: operator*, std::shared_ptr<T>:: operator->

From cppreference.net
Memory management library
( exposition only* )
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
( until C++20* )
( until C++20* )
( until C++20* )

Garbage collector support (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
T & operator * ( ) const noexcept ;
(1) (C++11부터)
T * operator - > ( ) const noexcept ;
(2) (C++11부터)

저장된 포인터를 역참조합니다. 저장된 포인터가 null인 경우 동작은 정의되지 않습니다.

목차

매개변수

(없음)

반환값

1) 저장된 포인터를 역참조한 결과, 즉 * get ( ) .
2) 저장된 포인터, 즉 get ( ) .

비고

T 배열 타입이거나 (가능한 cv-qualified) (C++17부터) void 인 경우, 함수 (1) 이 선언되는지 여부는 명시되지 않습니다. 선언되는 경우, 그 반환 타입이 무엇인지 명시되지 않으나, 함수의 선언(정의는 아니더라도)이 올바르게 형성되어야 합니다. 이로 인해 std:: shared_ptr < void > 의 인스턴스화가 가능해집니다.

T 가 배열 타입일 때, 함수 (2) 가 선언되는지 여부는 명시되지 않습니다. 선언될 경우, 해당 함수의 반환 타입이 무엇인지 명시되지 않으나, 함수 선언은 올바른 형태를 가져야 합니다.

(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

참고 항목

저장된 포인터를 반환합니다
(public member function)