14_1.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:0k
源码类别:

C#编程

开发平台:

Visual C++

  1. //14_1
  2. #include <iostream.h>
  3. class Samp{
  4. public:
  5.   void Setij(int a, int b){i=a,j=b;}
  6.   ~Samp(){ cout <<"Destroying.." <<i <<endl; }
  7.   int GetMulti(){ return i*j; }
  8. protected:
  9.   int i;
  10.   int j;
  11. };
  12. void main()
  13. {
  14.   Samp* p = new Samp[10];
  15.   if(!p){
  16.     cout <<"Allocation errorn";
  17.     return;
  18.   }
  19.   for(int j=0; j<10; j++)
  20.     p[j].Setij(j,j);
  21.   for(int k=0; k<10; k++)
  22.     cout <<"Multi[" <<k <<"] is:"
  23.          <<p[k].GetMulti() <<endl;
  24.   delete[]p;
  25. }