#include void foo() { boost::property_tree::ptree pt; auto myfunc = [=]() { boost::property_tree::ptree::const_iterator pos1 = pt.begin(); }; }