Code:int main() { vector< Base*> scene_; get_input(scene_); for(size_t i =0; i < scene_.size(); i++) { std::cout << scene_[i]->getSomething(); } return1; } void get_input( vector<Base*>&scene) { Derived obj_a(some_param); Derived obj_b(some_other_param); scene.push_back(dynamic_cast<Base*> (&obj_a)); scene.push_back(dynamic_cast<Base*> (&obj_b)); }
I also have
So I am trying to populate scene_ which is a vector of Base* objects which actually contains derived class objects;Code:class Derived : public Base {};
I am encountering a segmentation fault in this code while I am iterating through the scene_