Create a two-dimensional array of objects.
#include <iostream>
using namespace std;
class MyClass {
int a;
public:
MyClass(int n) {
a = n;
}
int getA() {
return a;
}
};
int main()
{
MyClass ob[4][2] = {
1, 2,
3, 4,
5, 6,
7, 8
};
int i;
for(i = 0; i <4; i++) {
cout << ob[ i ][0].getA() << ' ';
cout << ob[ i ][1].getA() << endl;
}
cout << endl;
return 0;
}
Related examples in the same category