Fixing with auto_ptr void some_function(string name) { Person *fredp = new Person(name); auto_ptr fred(fredp); fred->setName(name); }