기본 콘텐츠로 건너뛰기

증가 연산자 구현하기 (++ operator)

자꾸 까먹어서 기록해본다.


class MyClass {
    MyClass& operator++() { /* \todo 증분하기: ++MyClass */ return *this; }
    MyClass operator++(int) { /* MyClass++ */ MyClass tmp(*this); operator ++ (); return tmp; }

};

operator ++(int)에서 int는 전위(prefix)와 후위(postfix) 연산자를 컴파일러가 구분하기 위해서 넣는 힌트일 뿐이다.

참조: http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Fcplr330.htm

댓글

이 블로그의 인기 게시물

Winget 해시 무시하기

가끔씩 Winget 에서 패키지를 다운로드 했을 때, "설치 관리자 해시가 일치하지 않습니다." 오류가 뜰 때가 있다. 보안 이슈가 있지만, 그냥 무시하고 싶을 때, 아래 순서로 무시해준다. 관리자 권한 winget settings --enable InstallerHashOverride 설치 winget install --ignore-security-hash --id NirSoft.NirCmd