The this Pointer - C++ Class

C++ examples for Class:this

Introduction

The this pointer contains the address of current object.

class Pool
{
private:
  double length;
  double width;
  double height;

public:
  // Constructors
  Pool(double lv = 1.0, double wv = 1.0, double hv = 1.0);

  double volume();                                  // Function to calculate the volume of a pool

};

The volume() method can access the member fields as follows:

double Pool::volume()
{
  return this->length * this->width * this->height;
}

Related Tutorials