pointer changes to nullptr after deleting