I have a pointer to an int.
int index = 3;
int * index_ptr = &index;
index_ptr is a member variable of a class IndexHandler.
class A has a std::vector of IndexHandlers, Avector.
class B has a std::vector of pointers to IndexHandlers, Bvector, which I set to point to the items in class A’s vector, thusly:
Bvector.push_back(Avector[i].GetPtr())
With me so far?
I want to check that when I resolve the pointers in Bvector, and retreive the internal IndexHandlers index_ptr, that they point to the same index_ptr as class A’s…
How can I check they are pointing to the same memory address?…
How do i print the address of the value pointed to by both sets of pointers?
the non-iterator method to print them out side-by-side:
This will print out the pointer values of each one.
One thing you should be aware of though. If the pointer in the IndexHandler is pointing to a value within the IndexHandler then it can become invalidated if the vector is resized, and pointers to anything above an index WILL be invalidated if an item is inserted or deleted at that index. Because of this, it’s generally a bad idea to keep pointers to items in a vector and if you want to do this then it’s better practice to use a std::list container instead (which doesn’t invalidate pointers to items in the list when you insert or delete new values)