programming-examples/c++/Others/Arrays of Objects.cpp
2019-11-15 12:59:38 +01:00

24 lines
370 B
C++

Arrays of Objects
#include <iostream>
using namespace std;
class MyClass {
int i;
public:
void setInt(int j) {
i=j;
}
int getInt() {
return i;
}
};
int main()
{
MyClass myObject[3];
int i;
for(i=0; i<3; i++)
myObject[i].setInt(i+1);
for(i=0; i<3; i++)
cout << myObject[i].getInt() << "\n";
return 0;
}