1 #include <iostream> 2 #include <cstdlib> 3 using namespace std; 4 5 struct info 6 { 7 int id; 8 int num; 9 //堆上面开辟内存必须有构造函数 10 info(int nid, int nnum) :id(nid), num(nnum)//构造函数 11 { 12 13 } 14 }; 15 16 void main() 17 { 18 info *p = new info[2]{ {1,3},{2,3} }; 19 for (int i=0;i<2;i++) 20 { 21 cout << p[i].id << " " << p[i].num << endl; 22 } 23 24 25 cin.get(); 26 }