#include <iostream>
#include <vector>
class MyClass {
public:
int value;
MyClass(int val) : value(val) {}
};
int main() {
std::vector<MyClass*> myVector;
// Populate vector with pointers to MyClass objects
for (int i = 0; i < 5; ++i) {
myVector.push_back(new MyClass(i));
}
// Iterate over the vector of pointers using iterators
for (std::vector<MyClass*>::iterator it = myVector.begin(); it != myVector.end(); ++it) {
// Access the object through the pointer and perform some operation
std::cout << (*it)->value << " ";
}
// Don't forget to free the memory allocated for MyClass objects
for (MyClass* ptr : myVector) {
delete ptr;
}
return 0;
}