Cover by Joe Conway, Aaron Hillegass

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

Using Instances

In order to use an instance of a class (an object), you must have a variable that points to the object. A pointer variable stores the location of an object in memory, not the object itself. (It points to the object.) A variable that points to an object is declared like so:

P​a​r​t​y​ ​*​p​a​r​t​y​I​n​s​t​a​n​c​e​;​

This variable is named partyInstance. It is meant to be a pointer to an instance of the class Party. However, this does not create a Party instance – only a variable that can point to a Party object.

Creating objects

An object has a life span: it is created, sent messages, and then destroyed when it is no longer needed.

To create an object, you send an alloc message to a class. In response, the class creates an ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required