![]() |
![]() |
![]() |
![]() |
![]() |
|
Similarly, you can tie a pointer variable to a run-timeallocated
chunk of memory for a cylinder object using an
assignment statement:
*----- Refers to a memory location that can hold the address | of a chunk of memory allocated for a cylinder | | *----- Returns the address of a chunk of memory allocated | | for a cylinder at run time v v cptr = new cylinder;
When you use such a statement to allocate memory for a class object, your program automatically calls the default constructor function.
Note that the definition of the cylinder pointer, cptr, does
not cause your program to call a cylinder constructor. A
cylinder constructor is called only when space for the
cylinder object is allocated by new.
Later, in the hardcopy version of this book, you see that you can also arrange
to have new statements call constructors with arguments instead of
the default constructor.