これが取引です。クラスFとクラスOの2つの異なるクラスがあります
class F {
private:
int x;
int y;
public:
int getXf(){ return x; }
int getYf(){ return y; }
f(int ,int);
};
class O {
private:
int n;
int k;
int x;
int y;
char type;
int id;
int t;
public:
O(int ,int ,int ,int ,int);
int getX(){ return x; }
int getY(){ return y; }
};
そして、値を初期化する3番目のクラスPがあります。クラスでは、オブジェクトの2つの配列を作成しています。
class Prog {
public:
int count;
int fcount;
O *o[]; //here we are declaring the arrays of objects
F *f[];
public :
//void init(); Here is the function where we initializing the values
};
ここで、オブジェクトを作成しているステートメントの2つです。
for(int i=0;i<10;i++){
randx = rand() % 10;
randy = rand() % 20;
o[i] = new O(100,50,i,randx,randy);
}
for(int i=0;i<3;i++){
randx = rand() % 10;
randy = rand() % 10;
f[i] = new F(randx, randy);
}
印刷するとき、すべてのオブジェクトがここにありますが、最初のクラスの最初の3つは秒のオブジェクトに置き換えられます。正確には、それぞれ100
と50
(1st for)fromrandx
とrandy
(2nd for)です。