강의

멘토링

커뮤니티

Inflearn Community Q&A

johncoder's profile image
johncoder

asked

Following and Learning C++ with Hong Jeong-mo

15.3 Move constructors and move assignments

[12:40] Rvalue 참조 생성자 질문

Written on

·

390

0

안녕하세요! 디버거 찍어보다가 모르는 부분이있어

질문드립니다.

AutoPtr<Resource> generateResource()

{

AutoPtr<Resource> res(new Resource(10000000)); 

return res;

}

generateResource() 함수에서 return res;  부분에서 

res를 리턴을 하게 되어있는데 여기서 디버거를 찍어보니

AutoPtr 클래스의 AutoPtr(AutoPtr&& a) rvalue를 

오버로딩하는 함수로 진입이 되더라구요.

AutoPtr(AutoPtr&& a)에서 어떻게 함수 파라메터로 

들어오는지 잘 모르겠어요 ㅠㅠ

C++

Answer 2

2

"혹시..리턴한 res가 rvalue로  취급되어서AutoPtr(AutoPtr&& a)로 들어가는건가요..?" 👉 네 맞습니다. 함수 리턴값은 R-value 에요 :) 파라미터가 R-value 이기 때문에 이동생성자가 호출되는 것입니다.

1

asdfaa22님의 프로필 이미지
asdfaa22
Questioner

혹시..리턴한 res가 rvalue로  취급되어서AutoPtr(AutoPtr&& a)로 들어가는건가요..?

johncoder's profile image
johncoder

asked

Ask a question