#include <iostream>
using namespace std;
class Chulsoo
{
private:
int age;
public:
Chulsoo(int age)
{
this->age = age;
cout << "Chulsoo::Chulsoo(age) 생성자 완료" << endl;
}
void setAge(int age)
{
this->age = age;
}
void introduce()
{
cout << "철수의 나이는 " << age << "세 입니다." << endl;
Chulsoo returnThis()
{
return *this;
}
};
int main(void)
{
Chulsoo chulsoo3(32);
cout << "chulsoo introduce" << endl;
chulsoo3.returnThis().introduce();
chulsoo3.returnThis().setAge(50);
chulsoo3.returnThis().introduce();
return 0;
}
결과가 32 초기에 넣은 32라는 값이 50으로 변경이 안되는데 책에는 "*this 값이 지역 변수와 성격이 같아서 함수가 반환하면 *this 값이 소멸한다" 라고 하는데 이해가 잘 안되요 쉽게좀 설명해주실분...
형님은 객체를 복사해버린 것이여
되요->돼요 (되어 = 돼임) [리듬 맞춤법 봇♬]