this 포인터
this 포인터
#include <iostream>
using namespace std;
class Point {
int x;
int y;
public :
Point(int x = 0, int y = 0) : x(x), y(y) {
cout << "객체 생성" << endl;
}
void add(int x, int y = 0) {
this->x += x;
this->y += y;
}
void show() {
cout << "[" << x << "," << y << "]" << endl;
}
};
int main() {
Point p1(10, 50);
Point p2(20);
p1.add(20, -10);
p2.add(5, 23);
p1.show();
p2.show();
}자기 자신 참조자(Self Reference) 반환
Last updated