Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::vector<Parent*> list_of_pars;
- int i;
- for (each line in file){ /// pseudocode for opening and iterating through a filestream
- Parent* par = new Parent();
- vector<string> linedata = line.split(":")
- par->id = linedata[0];
- if (linedata[1] =="red"){
- Red red = Red::FromItem(par);
- red.reds_special_value = linedata[2];
- par = &red;
- }
- list_of_pars.push_back(par);
- i++;
- }
- The problem is that red keeps getting redefined each loop such that all of them end up having the same ID and special value
- Red Red::FromItem(Parent* item){
- Red newRed;
- newRed.id = item->id;
- return newRed;
- }
Advertisement
Add Comment
Please, Sign In to add comment