Dynamic Memory Allocation for Objects


SUBMITTED BY: RavishBhatt

DATE: June 29, 2016, 10:05 a.m.

FORMAT: C++

SIZE: 336 Bytes

HITS: 507

  1. #include <iostream>
  2. using namespace std;
  3. class Box
  4. {
  5. public:
  6. Box() {
  7. cout << "Constructor called!" <<endl;
  8. }
  9. ~Box() {
  10. cout << "Destructor called!" <<endl;
  11. }
  12. };
  13. int main( )
  14. {
  15. Box* myBoxArray = new Box[4];
  16. delete [] myBoxArray; // Delete array
  17. return 0;
  18. }

comments powered by Disqus