testing if a shared_ptr is NULL

醉酒当歌 提交于 2019-12-05 00:54:33

Yes, you are testing it correctly.

Your problem, however, is likely caused by dereferencing an invalid iterator. Check that returnsAnIterator() always returns an iterator that is not vector.end() and the vector is not modified in between, or empty.

Yes, the code you have above is correct. shared_ptr can be implicitly converted to a bool to check for null-ness.

The problem you have is your returnAnIterator() function is returning an invalid iterator. Probably it is returning end() for some container, which is one past the end of the container, and thus cannot be dereferenced as you're doing with *it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!