In my code a have a global vector of Node object and a local vector of Node pointers:
#include
#include
#include
What you are doing is undefined behavior for your vector p because the vector v can change where it's objects are stored.
A std::vector's memory is contiguous, so it may, after a number of push_backs, have to allocate a new block memory and copy it's contents to the new block. This will invalidate all the pointers that happened to point to the old memory location.