看c++知识不短时间了,原来一直不知道空悬指针和野指针什么区别,一直以为它们是一个意思,而且不靠谱的度娘也没给我靠谱的解释。在yahoo answers看到了很不错的解释:
A dangling pointer is a pointer that used to point to a valid address but now no longer does. This is usually due to that memory location being freed up and no longer available. There is nothing wrong with having a dangling pointer unless you try to access the memory location pointed at by that pointer. It is always best practise not to have or leave dangling pointers.
空悬指针是这样一种指针:它曾经指向一个有效地址,但是现在不再指向有效地址(个人添加,其实就是原来的那块地址不能通过这个指针区访问了)。这通常是因为指针所指的内存单位被释放了并且不再有效了。空悬指针存在并没有什么问题,除非你尝试通过这个指针访问指向的地址空间。不遗留任何悬空指针总是最好的实践方式。
A wild pointer is a pointer that has not been correctly initialised and therefore points to some random piece of memory. It is a serious error to have wild pointers.
而野指针是这样一种指针:它没有被正确的初始化于是指向一个随机的内存地址。存在野指针是一个严重的错误。
A dangling pointer is a pointer that used to point to a valid address but now no longer does. This is usually due to that memory location being freed up and no longer available. There is nothing wrong with having a dangling pointer unless you try to access the memory location pointed at by that pointer. It is always best practise not to have or leave dangling pointers.
空悬指针是这样一种指针:它曾经指向一个有效地址,但是现在不再指向有效地址(个人添加,其实就是原来的那块地址不能通过这个指针区访问了)。这通常是因为指针所指的内存单位被释放了并且不再有效了。空悬指针存在并没有什么问题,除非你尝试通过这个指针访问指向的地址空间。不遗留任何悬空指针总是最好的实践方式。
A wild pointer is a pointer that has not been correctly initialised and therefore points to some random piece of memory. It is a serious error to have wild pointers.
而野指针是这样一种指针:它没有被正确的初始化于是指向一个随机的内存地址。存在野指针是一个严重的错误。