类对象数组初始化

#include<iostream>
using namespace std;

class myclass{
 int a;
 int b;
public:
 myclass(int x,int y){a=x;b=y;}
 void show(){cout<<" a is "<<a<<"b is "<<b<<endl;}
};

int main()
{
 myclass cl[2]={myclass(1,2),myclass(3,4)};
 cl[0].show();
 cl[1].show();
 return 0;
}

 

测试结果:

 a is 1b is 2
 a is 3b is 4
Press any key to continue

你可能感兴趣的:(类对象数组初始化)