You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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;
}