我从空的std容器的front()中得到什么? [英] What do I get from front() of empty std container?
本文介绍了我从空的std容器的front()中得到什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果 front()
返回一个引用并且容器为空,我将得到什么,一个未定义的引用?这是否意味着我需要在每个 front()
之前检查 empty()
?
If front()
returns a reference and the container is empty what do I get, an undefined reference? Does it mean I need to check empty()
before each front()
?
推荐答案
您得到未定义的行为-您需要在调用front()之前使用empty()(检查容器是否为空)检查容器是否包含某些东西.
You get undefined behaviour - you need to check that the container contains something using empty() (which checks if the container is empty) before calling front().
这篇关于我从空的std容器的front()中得到什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文