this keyword usage

All QuestionsCategory: Cpp Languagethis keyword usage
Anonymous asked 3 years ago
1 Answers
Anonymous answered 3 years ago

this keyword holds the address object by which the member function is invoked. It’s a hidden parameter for every nonstatic member function.
 
Mapping of class member functions in C++ vs normal functions in C

Customer class with data + operations 
     ==> struct Customer with only data

void Customer::recharge(double amt);
     ==> recharge(Customer* this, double amt);

void Customer::recharge(double amt) { balance += amt; }
     ==> voidrecharge(Customer* this, double amt) {
           this->balance+=amt;
         }

c1.recharge(100); ==> recharge(&c1, 100);