RugnirViking

Untitled

Dec 20th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1.  
  2. std::vector<Parent*> list_of_pars;
  3. int i;
  4. for (each line in file){ /// pseudocode for opening and iterating through a filestream
  5. Parent* par = new Parent();
  6. vector<string> linedata = line.split(":")
  7. par->id = linedata[0];
  8. if (linedata[1] =="red"){
  9. Red red = Red::FromItem(par);
  10. red.reds_special_value = linedata[2];
  11. par = &red;
  12. }
  13. list_of_pars.push_back(par);
  14. i++;
  15. }
  16.  
  17. The problem is that red keeps getting redefined each loop such that all of them end up having the same ID and special value
  18.  
  19. Red Red::FromItem(Parent* item){
  20. Red newRed;
  21. newRed.id = item->id;
  22. return newRed;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment