gpt4 book ai didi

c++ - 容器前后行为

转载 作者:太空狗 更新时间:2023-10-29 20:10:06 26 4
gpt4 key购买 nike

引用自《Effective STL》:

When you get an object from a container (via. e.g., front or back), what you set is a copy of what was contained. Copy in, copy out. That's the STL way.

我很难理解这部分。据我所知,front 返回第一个元素的引用(至少对于 std::vector 而言)。你能解释一下上面的句子吗?

最佳答案

这实际上是本书早期版本中的一个错误。来自errata :

! 6/29/01 jk     20  The first para of Item 3 is incorrect:  front      7/25/04
and back do NOT return copies of elements, they
return references to elements. I
removed all mention of front and back.

所以这句话的解释是:哎呀,是时候得到一个新版本了!

关于c++ - 容器前后行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42097795/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com