Soft Ware/C++ 언어!!

this 키워드 !!

달려가보자 2011. 10. 6. 01:04
this 키워드란!!!

->this 는 현재 주소값을 가르키는 키워드이다 .

예를  통해서 이해해보자.

class Person
{
      public:
                Person * GetThis(){
                              return this;
                                         }
              
}; 

int main()
{
          Person *p1 = new Person();
          cout<<"포인터 p1:"<<p1<<endl;  
          cout<<"p1의 this "<<p1->GetThis()<<endl; 


이것 처럼 리턴 값인 this 키워드를 통해서 Person의 주소값이랑 같다는것을 알수 있다 !!!