#include #include using namespace std; class BASE { public: virtual int print() const = 0; }; class CHILD: public BASE { public: CHILD(int a) : i(a) { } int i; virtual int print() const { return i; } }; int main() { // removing const causes it to compile boost::ptr_list intList; boost::ptr_list::iterator iterIntList; BASE *a = new CHILD(1); BASE *b = new CHILD(2); BASE *c = new CHILD(3); intList.push_back(a); intList.push_back(b); intList.push_back(c); for (iterIntList = intList.begin(); iterIntList != intList.end(); iterIntList++) { cout << iterIntList->print() << endl; } intList.clear(); // All pointers held in list are deleted. }