Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program received signal SIGSEGV, Segmentation fault.
- 0x0000400b5c in addComponent (oneList=..., oneComponent=@0x7ffffe08: 0x6120) at main.cpp:51
- 51 oneList.components[oneList.nElements++] = *oneComponent;
- (gdb) backtrace
- #0 0x00000400b5c in addComponent (oneList=..., oneComponent=@0x7ffffe08: 0x6120) at main.cpp:51
- #1 0x00000000bf6 in main () at main.cpp:69
- (gdb)
- struct Component
- {
- int piece1;
- int piece2;
- int piece3;
- int piece4;
- };
- struct ListComponentDynamic
- {
- Component* components;
- int capacity;
- int nElements;
- };
- void addComponent(ListComponentDynamic& oneList, Component*& oneComponent)
- {
- if (oneList.capacity == oneList.nElements)
- doubleCapacity(oneList);
- oneList.components[oneList.nElements++] = *oneComponent;
- }
- void freeAllocatedList(ListComponentDynamic& oneList)
- {
- delete[] oneList.components;
- oneList = {};
- }
- int main()
- {
- // add an element
- ListComponentDynamic oneList;
- oneList.components = {0};
- // adding the value 2 to piece1;
- Component* component1 = new Component{2, 0, 0 ,0};
- addComponent(oneList, component1);
- std::cout << component1->piece1;
- }
Add Comment
Please, Sign In to add comment