previous | start | next

10. Pointers and Classes - Alternate Syntax

For a pointer to a class type, it is much more common to use a single operator, -> for member access than the two operator combination above (dereferencing operator plus the member access operator).

int main()
{
  Car myHybrid(30);

  Car *p = &myHybrid;

  myHybrid.addGas(20);

// equivalent to:

  p->addGas(20);

  myHybrid.drive(100);

// equivalent to:

  p->drive(100);
  ...
}


previous | start | next