gpt4 book ai didi

c++ - const map 和 map of const elements 的区别

转载 作者:行者123 更新时间:2023-11-28 01:14:10 27 4
gpt4 key购买 nike

这些 map 之间有区别吗?什么时候应该使用它们?

const map<string, vector<unsigned char>> map1;
const map<const string, const vector<unsigned char>> map2;
const map<const string, const vector<const unsigned char>> map3;
map<const string, const vector<unsigned char>> map4;
map<const string, const vector<const unsigned char>> map5;

最佳答案

拥有一个const 容器意味着该容器是不可变的。你无法改变它。

拥有一个非const 容器意味着该容器是可变的。您可以更改它。

更改映射意味着:向其中添加内容、修改其中包含的内容(如果它们本身是可变的)、从中删除。

顺便说一下,putting const on a map key is largely pointless .

我不打算列举“什么时候应该使用它们”;您使用正确的工具来完成工作,并且有几乎无限多的可能工作。

关于c++ - const map 和 map of const elements 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59251176/

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