红移中的宇宙 2022-06-13 14:02 采纳率: 100%
浏览 31
已结题

指针值的四个状态是什么意思?

拿《C++ primer》自学C++,书上说指针的值有四种可能状态。其中一个说“指向紧邻对象所占空间的下一个位置”,这是什么意思?
最后一种是“无效指针”,什么时候才会出现无效指针?请大家赐教。

  • 写回答

2条回答 默认 最新

  • 假装不困 2022-06-13 14:33
    关注

    无效指针一般是释放对应的对象,但是你没把指针指向 nullptr,图中的 tmp 已经被释放了,tmp 本身还是有值,指向的内容被释放了

    img

    指向紧邻对象所占空间的下一个位置:你继续往后看,看到容器的相关的章节,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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 6月23日
  • 已采纳回答 6月15日
  • 创建了问题 6月13日

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大