Skip to content
  • this Pointer · OOPs

this Pointer

LearnViaNotes @learnvianotes· 1 min read

A special hidden pointer in every member function that points to the object that called the function.

C++
class Teacher {

  string name;

  public:

    void setName(string name) {

      // 'name' (param) shadows 'name' (member)

      this->name = name;  // this->name = member

    }

};


// this->prop is the same as (*this).prop

// Used in copy constructor to avoid ambiguity

Free for students and teachers

Write notes like this one

Cards for every idea, quizzes and flashcards, read aloud — on the web and your phone.

Something wrong with this note? Open it to report