개발/C, C++

[C++] this 포인터

huiyu 2018. 12. 16. 14:12

this

- 객체 자신의 주소값을 의미

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
 
using namespace std;
 
class TwoNumber
{
private:
  int num1;
  int num2;
 
public:
  TwoNumber(int num1, int num2)
  {
    this->num1 = num1;
    this->num2 = num2;
  }
  TwoNumber(int num1, int num2)
      : num1(num1), num2(num2)
  {
     //empty 
  }
  void ShowTwoNumber()
  {
    cout<< this->num1 <<endl;
    cout<< this->num2 <<Endl;
  }
};
 
int main(void)
{
  TwoNumber two(2,4);
  two.ShowTwoNumber();
  return 0;
}
cs


* 클래스의 this관련 공부자료

1) this의 컴파일 

2) 함수포인터의 this 

3) 멤버변수의 포인터

4) 다중상속의 멤버함수 포인터 

728x90
반응형