C++ this
this 다시 한번 복기해보도록 하자. 멤버 변수는 객체별로 따로 메모리가 할당되고 멤버 함수는 클래스에 속하는 모든 객체들이 하나의 메모리를 공유하는것을 알고 있을 것이다. 그러면 다음 코드를 보도록 하자. #include class Thing { private: int num; public: Thing(int n) : num(n) {} void OutValue() { std::cout num) return Other; else return this; } // 레퍼런스를 보낼 경우 Thing& getBigger(Thing& Other) { if (Other.num > num) return Other; else return *this; } A.getBigger(&B)->OutValue(); // call..
C++/C++98
2023. 8. 5. 11:56