I'm having terrible time trying to make a while inside a while sequence
I have a list of Departments and in every Department there is list of Courses who is given by this department in addition a Course class holds a list of students inside him...
now...
I want to insert a student to a specific Course, (lets say I have all the student details...) 4 that i'm passing all the departments list 1 by 1 in a while loop and for evry department I'm doing another while iteration in order to find the correct course (I know the wanted course)
so what is going in the running of the program is that the first iteration works and inserting the student for the correct course but after that in the second time that I'm getting inside this part of code my ptr is holding Garbage and is not up-to-date I mean not holding the correct list of courses
I'm working with stl <list> and all I need is to do an update to the pointer for the cours list...
I searched google till my soul came out suicide...
Thanks in advance for all the helpers...
Here is the sequence...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
else if (!strcmp("2",part2.c_str()) )
{
getline(ss2, part2, ',');
string Wanted_ID = part2; //"Wanted_ID" holds the student ID
getline(ss2, part2, ',');
string cours_number = part2; // cours number
list<CountedPtr<Student>>::iterator stu_TMP = College_M.Student_List_in_the_College.begin();// start of the students list
CountedPtr<Student> s_demo; //sheard pointer.
Student* _Student = new Student;//sheard pointer.
s_demo.ptr = (_Student);//sheard pointer.
s_demo.ptr=NULL;
while(stu_TMP != College_M.Student_List_in_the_College.end())//student sheal
{
if(stu_TMP->ptr->get_m_id()==atoi(Wanted_ID.c_str())) //if it is the correct ID (student)
{
s_demo.ptr = stu_TMP->ptr;
//s_demo is a copy of the correct student
}
stu_TMP++;
}
list<Department>::iterator current5 = College_M.Department_List.begin(); // strat of the Department list
list<Cours>::iterator Curr_at_specific_cours = College_M.Department_List._Myhead->_Next->_Myval.Cours_Name_List.begin();
while(current5 != College_M.Department_List.end() ) //Departments sheal
{
list<Department>::iterator current5 = College_M.Department_List.begin(); // strat of the Department list
//list<Cours>::iterator Curr_at_specific_cours = College_M.Department_List._Myhead->_Next->_Myval.Cours_Name_List.begin();
while(Curr_at_specific_cours != College_M.Department_List._Myhead->_Next->_Myval.Cours_Name_List.end())//cours sheal
{
if( Curr_at_specific_cours->get_m_cours_number() == atoi(cours_number.c_str()) ) // if we find the wanted cours
{
//now we are in the correct cours at the correct department and will push the correct student
Curr_at_specific_cours->Student_List.push_back(s_demo);
goto Out;
}
Curr_at_specific_cours++;
}
current5++;
College_M.Department_List.rbegin();
}
Out:
cout<<"Operation 2 finished successfully"<<endl;
}
| |
I added the whole file ... (to see the problem running)...
http://www.2shared.com/file/kG9P5Gho/reference_counting.html
again hanks in advance for all the helpers...