091-C++

对象的动态内存分配

#include <iostream>
using namespace std;
 
class Box
{
   public:
      Box() { 
         cout << "调用构造函数!" <<endl; 
      }
      ~Box() { 
         cout << "调用析构函数!" <<endl; 
      }
};
 
int main( )
{
   Box* myBoxArray = new Box[4];
 
   delete [] myBoxArray; // Delete array
 
   return 0;
}


猜你喜欢

转载自blog.csdn.net/xiaofeng3011/article/details/72973604