/* File: main3.C Use the Box class. */ #include #include "box1.h" main() { Box boxes[4] ; /* array of 4 boxes */ Box *bptr ; int i, items ; printf("Automatically allocated array of boxes:\n") ; for (i = 0 ; i < 4 ; i++) { printf("boxes[%d]: ", i) ; boxes[i].identify() ; } printf("\nA dynamically allocated box\n") ; bptr = new Box ; /* same as malloc(sizeof(Box)) */ (*bptr).identify() ; bptr->identify() ; delete bptr ; /* same as free(bptr) */ printf("\nDynamically allocated array of boxes:\n") ; items = 7 ; bptr = new Box[items] ; /* same as malloc(items * sizeof(Box)) */ for (i = 0 ; i < items ; i++) { printf("bptr[%d]: ", i) ; bptr[i].identify() ; } delete [] bptr ; /* same as free(bptr) */ }