강의

멘토링

커뮤니티

Inflearn Community Q&A

khb4435's profile image
khb4435

asked

Following and Learning C++ with Hong Jeong-mo

9.5 Overloading Increment and Decrement Operators

질문

Written on

·

325

0

 Digit& operator++ (int)

    {

        Digit temp(m_digit);

        ++(*this);

        //++m_digit;

        return temp;

    }

제가 알기로 *this는 객체 그 자체라고 알고 있는데

++(*this) == ++m_digit 이 가능한가요?

*this는 객체 그 자체이고 m_digit은 객체의 멤버변수인데요!

C++

Answer 3

0

그 문제는 operator++를 어떻게 구현하느냐에 따라 달려있습니다.

0

khb4435님의 프로필 이미지
khb4435
Questioner

++(*this) ++객체를 하게되면 객체의 멤벼변수가 + 되나요?

0

원하는대로 구현하려면 ++ operator 내부에서는 ++m_digit 를 해야합니다.

지금 구조는 재귀적인 구조가 되어있으며... reference로 return을 하고 계시는군요. 이는 문제를 일으킬 수 있습니다.

다른 함수 내에서 ++(*this) 를 하시면 생각하신대로 작동합니다.

khb4435's profile image
khb4435

asked

Ask a question