By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,227 Members | 1,176 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,227 IT Pros & Developers. It's quick & easy.

<map> and const objects

P: n/a
Hi, I have a question about map and classes that contain maps. My problem
is declaring any class methods const that would do something to the map.
Presumably it's because when operator[] is accessed, the map object can be
changed. Is there any way that I can somehow say that I'm not going to
change the map object?

Also, it becomes a problem when I try to declare the copy constructor like
this:

class A {
A(const A& x); // this has a problem, and has to be A(A& x)
};

any help on this would be appreciated. Thanks.

S.
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Thanks, I ended up using const_iterators instead.

S
"John Harrison" <jo*************@hotmail.com> wrote in message
news:bg************@ID-196037.news.uni-berlin.de...

"john smith" <as**@asdf123asdf.net> wrote in message
news:bg***********@news.eecs.umich.edu...
Hi, I have a question about map and classes that contain maps. My problem is declaring any class methods const that would do something to the map.
Presumably it's because when operator[] is accessed, the map object can be changed. Is there any way that I can somehow say that I'm not going to
change the map object?


Use find instead of operator[]. find cannot alter the map.

john

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.