Main Index : Reference :

this


Description

A reference to the current object.

Value

this acts as a reference to the current object. It can only be used in member functions of classes or structures.

Example

// When calling member classes, a leading
// "this->" is always assumed.

class myClass
{
private:
  var length;
public:
  myClass(x); // Constructor
  setLength(x);
}

myClass::myClass(x)
{ 
  // These two are the same:
  setLength(x);
  this->setLength(x);
}

myClass::setLength(x)
{
  length = x;
}


// Another usage example. The Engine object assigns
// a reference to itself to the global variable
// active_engine.

var active_engine;

Engine::Activate()
{
  active_engine = this;
}

See Also

class