Guest User

Untitled

a guest
Oct 17th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. Program received signal SIGSEGV, Segmentation fault.
  2. 0x0000400b5c in addComponent (oneList=..., oneComponent=@0x7ffffe08: 0x6120) at main.cpp:51
  3. 51 oneList.components[oneList.nElements++] = *oneComponent;
  4. (gdb) backtrace
  5. #0 0x00000400b5c in addComponent (oneList=..., oneComponent=@0x7ffffe08: 0x6120) at main.cpp:51
  6. #1 0x00000000bf6 in main () at main.cpp:69
  7. (gdb)
  8.  
  9. struct Component
  10. {
  11. int piece1;
  12. int piece2;
  13. int piece3;
  14. int piece4;
  15. };
  16. struct ListComponentDynamic
  17. {
  18. Component* components;
  19. int capacity;
  20. int nElements;
  21. };
  22.  
  23. void addComponent(ListComponentDynamic& oneList, Component*& oneComponent)
  24. {
  25. if (oneList.capacity == oneList.nElements)
  26. doubleCapacity(oneList);
  27.  
  28. oneList.components[oneList.nElements++] = *oneComponent;
  29. }
  30.  
  31. void freeAllocatedList(ListComponentDynamic& oneList)
  32. {
  33. delete[] oneList.components;
  34. oneList = {};
  35. }
  36.  
  37. int main()
  38. {
  39. // add an element
  40. ListComponentDynamic oneList;
  41. oneList.components = {0};
  42.  
  43. // adding the value 2 to piece1;
  44. Component* component1 = new Component{2, 0, 0 ,0};
  45.  
  46. addComponent(oneList, component1);
  47. std::cout << component1->piece1;
  48. }
Add Comment
Please, Sign In to add comment