This might be a simple question but I am trying to initialize an array of objects using a parameterized constructor. For example:
class A{
public:
int b,c,d;
A (int i, int j);
};
void A::A(int i, int j){
d = rand()
b = 2*i;
c = 3*j;
}
void main(){
A a[50]; /*Initialize the 50 objects using the constructor*/
}
I have already tried with vector initialization as mentioned in this link however, since there are 2 parameters, this does not work.
Also, as mentioned in this link, it is not possible and tedious to manually enter 50 initialization values.
Is there a easier way. Also, i,j values are the same for all objects (available through main()) but d
should be random value and differs from each object.