
What's wrong with this code? When I push_back ptr to the vector, it pushes 0 instead of the value contained in ptr (which I checked and is non-zero).
std::vector<boost::shared_ptr<BaseClass> > baseobjects = get_base_objects(path);
std::vector<boost::shared_ptr<DerivedClass> > result(get_base_objects.size());
Your problem is the line above. You're creating a vector of 'get_base_objects.size()' default-constructed shared pointers. Either use reserve() to grab that much space, or use assignment bellow.
BOOST_FOREACH (boost::shared_ptr<BaseClass> en, baseobjects) { boost::shared_ptr<DerivedClass> ptr = boost::dynamic_pointer_cast<DerivedClass>(en);
//Error when push_back. Instead of ptr, I get 0 result.push_back(ptr); }
-- Nikolai