2
中的前向声明类我设置了一个模拟类,它将所有模拟对象保存在ptr_list中。因为我需要快速访问所有的粒子,我添加了一个额外的ptr_list。现在鼓励抱怨,因为它不喜欢前进声明的类。已经向我指出recursive_wrapper
,但ptr_list< recursive_wrapper<Particle> >
似乎也不能工作。对于一个小型科学项目,boost :: ptr_list
#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();
}