Answers for "dynamicaly allocate memory for class c++"

C++
0

dynamicaly allocate memory for class c++

#include <iostream>
using namespace std;

class Box {
   public:
      Box() { 
         cout << "Constructor called!" <<endl; 
      }
      ~Box() { 
         cout << "Destructor called!" <<endl; 
      }
};
int main() {
   Box* myBoxArray = new Box[4];
   delete [] myBoxArray; // Delete array

   return 0;
}
Posted by: Guest on October-13-2021

Code answers related to "dynamicaly allocate memory for class c++"

Browse Popular Code Answers by Language