Classes and structs are different, structs can be initialized with {...} method is all assigned, but what about the struct? One is to write an array of data into the same structure, and then the For loop uses a non-constructor to write to the class array. Another method is to write directly to the corresponding array, for example, with one of the following classes:
Class a{
char* pname;
int property[5];
Public
void IPT (char* t,int pt[]) {pname=t;
for (int i=0;i<5;i++)
Property[i]=pt[i];
}
}
Use the first method as follows:
struct ac{
char* pname;
int property[5];
} inita[2]={{"A", 1,2,3,4,5},{"B", 2,3,4,5,6}};
This allows the IPT to be called:
A;
for (int i =0;i< 2;i++)
A.ipt (inita[i].pname,inita[i].property[]);
If you use the second method, you do not have to define the structure, as follows:
int pr[2][5]={{1,2,3,4,5},{2,3,4,5,6}};
char* pm[2]={"A", "B"};
Then use the For loop directly:
for (int i=0;i<2;i++)
A.ipt (Pm[i],pr[i]);
Which one do you think is simpler?
C + + class array Batch assignment value