boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 请教一个c++ map问题
相关主题
which func will be called?
C++ Strategies and Tactics 书上一个问题求助
请问c++为什么会编译失败?
菜鸟请教smart pointer
C++一问
c++ iterator 弱问
一个小程序差点搞死了g++,怎么回事?
问一个C++ set和unordered_set iterator的问题
一道C++面试编程题
问个BT问题 :)(c )
相关话题的讨论汇总
话题: dict话题: string话题: int话题: map话题: const
进入Programming版参与讨论
1 (共1页)
A**u
发帖数: 2458
1
我的函数是这样的
void build_dict(map& dict);
string number_to_string(int x, const map& dict); 这里有问题,加
上const,不能编译通过
int main(){
map dict;
build_dict(dict);
cout << number_to_string(888,dict);
return 0;
}
请问大家 难道stl里的模板类,不能象内置类型一样用 const T&吗?
多谢了
t****t
发帖数: 6806
2
你调用时是const那就要保证所有的操作都是const的

【在 A**u 的大作中提到】
: 我的函数是这样的
: void build_dict(map& dict);
: string number_to_string(int x, const map& dict); 这里有问题,加
: 上const,不能编译通过
: int main(){
: map dict;
: build_dict(dict);
: cout << number_to_string(888,dict);
: return 0;
: }

A**u
发帖数: 2458
3
谢谢你回复
我在string number_to_string(int x, const map& dict);
只用了 dict[index]方法,
看来dict[index]不是const 方法啊

【在 t****t 的大作中提到】
: 你调用时是const那就要保证所有的操作都是const的
D*******a
发帖数: 3688
4
it is not. if index does not exist in dict, an entry will be inserted.

【在 A**u 的大作中提到】
: 谢谢你回复
: 我在string number_to_string(int x, const map& dict);
: 只用了 dict[index]方法,
: 看来dict[index]不是const 方法啊

A**u
发帖数: 2458
5
恩 看书的时候也提到了
用的时候没注意.

【在 D*******a 的大作中提到】
: it is not. if index does not exist in dict, an entry will be inserted.
1 (共1页)
进入Programming版参与讨论
相关主题
问个BT问题 :)(c )
关于C++中一个Class的大小 (转载)
c++ 得最基本问题
[合集] C++问题(copy constructor)
C++ 的 问题
A aimple C++ question
关于C++ copy-constructor 一个奇怪的问题
为什么foo1可以而foo2不行?
问题
conversion between const to nonconst
相关话题的讨论汇总
话题: dict话题: string话题: int话题: map话题: const