Advertisement
Guest User

C to C++ woe

a guest
Dec 15th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. Porting code from C to C++. Among other things changing this:
  2.  
  3. struct foo x[count];
  4. for (unsigned i=0; i<count; i++) {
  5. x[count].XXX = YYY;
  6. ....
  7. function(&x);
  8. }
  9.  
  10. To this:
  11.  
  12. std::vector<struct foo> x;
  13. for (unsigned i=0; i<count; i++) {
  14. x.emplace_back(YYY, ...);
  15. function(&x);
  16. }
  17.  
  18. Surprise, surprise, I got unexpected errors when accessing the function's
  19. argument. Took me about 1h to figure out what's wrong. I think I'm gonna keep
  20. this as a potential interview question :-)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement