24学时攻克C++光盘源代码 深入浅出 方便实用

源代码在线查看: newarray.cpp

软件大小: 124 K
上传用户: a1a1J0
关键词: 光盘 源代码
下载地址: 免注册下载 普通下载 VIP

相关代码

				 // Listing 15.5 - An array on the heap

				 #include 

				 

				 class CAT

				 {

				 public:

				     CAT() { itsAge = 1; itsWeight=5; }      // default constructor

				     ~CAT();                                 // destructor

				     int GetAge() const { return itsAge; }

				     int GetWeight() const { return itsWeight; }

				     void SetAge(int age) { itsAge = age; }

				 

				 private:

				     int itsAge;

				     int itsWeight;

				 };

				 

				 CAT :: ~CAT()

				 {

				 //  std::cout 				 }

				 

				 int main()

				 {

				     CAT * Family = new CAT[500];

				     int i;

				     CAT * pCat;

				     for (i = 0; i < 500; i++)

				     {

				         pCat = new CAT;

				         pCat->SetAge(2*i +1);

				         Family[i] = *pCat;

				         delete pCat;

				     }

				 

				     for (i = 0; i < 500; i++)

				         std::cout 				             				 

				     delete [] Family;

				 

				     return 0;

				 } 

							

相关资源