강의

멘토링

커뮤니티

Inflearn Community Q&A

ghkddnjstlr1118745's profile image
ghkddnjstlr1118745

asked

[MMORPG Game Development with C++ and Unreal Series] Part 4: Game Server

Reference Counting

포인터 연산자 오버로딩

Written on

·

370

0

코드중에

T* operator*() { return _ptr; }

인 부분이있는데

T& operator*(){return *_ptr;}  로 해야 포인터 연산이 되는 것 아닌가요?

const T* operator*() const { return _ptr; }

const T* operator->() const { return _ptr; }

그리고 *연산자와 ->연산자의 const버전이 쓰이는 때가 언제인지 궁금합니다.

networkwindows-serverMMORPG

Answer 1

1

Rookiss님의 프로필 이미지
Rookiss
Instructor

T& operator*(){return *_ptr;}  로 해야 포인터 연산이 되는 것 아닌가요?

네 그렇게 수정하시면 됩니다. (표준 shared_ptr은 그게 맞겠네요)

그리고 *연산자와 ->연산자의 const버전이 쓰이는 때가 언제인지 궁금합니다.

말 그대로 const 객체를 대상으로 * ->하면 const 버전이 호출되는데
그 부분은 직접 테스트를 해보시기 바랍니다.
(ex. const WraightRef wraight(new Wraight()); ...)

fhan님의 프로필 이미지
fhan
Questioner

감사합니다!

ghkddnjstlr1118745's profile image
ghkddnjstlr1118745

asked

Ask a question