October 2011
Beginner to intermediate
1200 pages
35h 33m
English
You should note several points about using pointers to objects (refer to Figure 12.5 for a summary):
• You declare a pointer to an object by using the usual notation:
String * glamour;
• You can initialize a pointer to point to an existing object:
String * first = &sayings[0];
• You can initialize a pointer by using new. The following creates a new object:
String * favorite = new String(sayings[choice]);
Also see Figure 12.6 for a more detailed look at an example of initializing a pointer with new.
• Using new with a class invokes the appropriate class constructor to initialize the newly created object:
// invokes default constructorString * gleep = new String;// invokes the String(const char *) constructorString ...
Read now
Unlock full access