Initializing Dynamic Memory

You can provide an initializer for a newly created fundamental-type variable, as in

double *ptr = new double( 3.14159 );

which initializes a newly created double to 3.14159 and assigns the resulting pointer to ptr. The same syntax can be used to specify a comma-separated list of arguments to the constructor of an object. For example,

Time *timePtr = new Time( 12, 45, 0 );

initializes a new Time object to 12:45 PM and assigns the resulting pointer to timePtr.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.101.109