c++ - Accessing Iterator After Deletion Causes Crash -
so i'm used coding in c# , have started using c++ again after pretty substantial break. i'm trying create program has lists of students ids, in courses.
i have code prints out available students in courses.
auto allcourses = wsucourse::getallcourses(); std::for_each( allcourses.begin(), allcourses.end(), getcourseprinter());
the getcourseprinter()
called in code in constructor
struct getcourseprinter { void operator () ( mycourse *courseptr ) { std::cout << courseptr->getidentifier() << ": " << courseptr->gettitle() << std::endl; } };
my problem after delete enrollment so
myenrollment *enrollmentptr = myenrollment::findenrollment( mystudent::getstudentwithuniqueid(1000002), mycourse::getcoursewithidentifier("cs 2800") ); delete enrollmentptr;
and try print getcourseprinter crashes. believe because it's trying access doesn't exist. i'm wondering if there way call this
if (allcourses.current() != null) { getcourseprinter(); } else { //do nothing }
when call:
delete enrollmentptr;
you need remove item in environment.
Comments
Post a Comment