拿《C++ primer》自学C++,书上说指针的值有四种可能状态。其中一个说“指向紧邻对象所占空间的下一个位置”,这是什么意思?
最后一种是“无效指针”,什么时候才会出现无效指针?请大家赐教。
无效指针一般是释放对应的对象,但是你没把指针指向 nullptr,图中的 tmp 已经被释放了,tmp 本身还是有值,指向的内容被释放了
指向紧邻对象所占空间的下一个位置:你继续往后看,看到容器的相关的章节,end 指向的位置就是紧邻对象的下一个位置
Return iterator to end
Returns an iterator referring to the past-the-end element in the map container.
The past-the-end element is the theoretical element that would follow the last element in the map container. It does not point to any element, and thus shall not be dereferenced.
Because the ranges used by functions of the standard library do not include the element pointed by their closing iterator, this function is often used in combination with map::begin to specify a range including all the elements in the container.
If the container is empty, this function returns the same as map::begin.
int a[3];
int *p;
for (p=&a[0];p!=&a[3];p++) cout<<*p<<endl;
//其中&a[3]就是无效指针