Different types and structures, structures can use {...} initialization method when all of the assignment, but how do structure it? One is to write a data array within the same structure, and then recycled for a non-class constructor is written into the array. Another method is written directly into the array corresponding to, for example, as a class:
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];
}
}
Using 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 can be called the ipt:
A a;
for (int i =0;i< 2;i++ )
a.ipt(inita[i].pname,inita[i].property[]);
If you use the second method, it does not define this structure, the following:
Int Q [2] [5] = {{1,2,3,4,5}, {2,3,4,5,6}};
char* pm[2]={"a","b"};
Directly after using a for loop:
for(int i=0;i<2;i++)
a.ipt(pm[i],pr[i]);
Which do you think is more simple?
Reproduced in: https: //www.cnblogs.com/absudra/p/9557583.html