previous
|
index
|
next
Class Constructors
When the
ItemInfo
class is defined as above, a special method called a
constructor
is defined behind the scenes.
A constructor's name is always the same as the class name.
A constructor can be used with the
new
operator to dynamically create a new instance (object) of a class:
ItemInfo* item = new ItemInfo;
// note the absence of arguments
As with structs and arrays, the
new
operator returns a pointer to the object.
A constructor with no arguments, called the
default constructor
, does not initialize the object's instance variables.
previous
|
index
|
next