for a small science project I set up a Simulation class which holds all simulated Objects in a ptr_list. Because I need to have fast access to all Particles I added an additional ptr_list. Now boost complains, because it doesn't like forward declarated classes. recursive_wrapper
was already pointed out to me, but ptr_list< recursive_wrapper<Particle> >
seems to work neither.
#include <boost/ptr_container/ptr_list.hpp>
class SimulatedObject {
};
class Particle; // derived from SimulatedObject
class Simulation {
public:
void addObj(SimulatedObject *obj) {
simulatedObjects.push_back(obj);
}
void addObj(Particle *par) {
particles.push_back(par);
}
protected:
boost::ptr_list<SimulatedObject> simulatedObjects;
boost::ptr_list<Particle> particles;
};
int main(int argc, char** argv) {
Simulation sim();
}