Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) this

 

 

this is a keyword to obtain a pointer to a class instance's own address.

 

When using this to access member variables or member functions, this can be left out.

 

 

 

 

 

Example

 

struct Int
{
  //Constructor
  Int(const int i) : m_x(i) {}

  int GetValue()
  {
    //this can be omitted
    return this->m_x;
  }
  void SetValue(const int x)
  {
    //this can be omitted
    this->m_x = x;
  }

  const Int * const GetMe() { return this; }

  private:
  int m_x;
};

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict