I'm working on a collision engine and more specifically, I am trying to make a vector of relevant bodies in the world. To be able to access a specific body in the vector of bodies in the world that represents a specific object, I need to know which specific body represents that object. To do this I want to return a pointer to the body in the vector of bodies when you add a new body, but what happens when I remove a body? more specifically, what if I remove a body that is before the current body in the list of bodies, and the body's position in the array changes. Does my pointer still point to the correct location in memory?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Do the Java Integer and Double objects have unnece
- Why does const allow implicit conversion of refere
- thread_local variables initialization
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
After removing an element in a vector all elements after the removed element will be moved one position left. So either the pointer will point to some other element or to the deleted element if it was the last element in the vector.
If you add a new element then the vector can reallocate memory. So all pointers to the elements of the vector will be invalid.