Re: Maps
- From: Alamelu <Alamelu@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 22 Aug 2006 01:24:03 -0700
This is my scenario...
I have unsigned char constants defined in my class...
const unsigned char strKey1[] = "Key1";
const unsigned char strValue1[] = "Value1";
const unsigned char strKey2[] = "Key2";
const unsigned char strValue2[] = "Value2";
I want these data to be populated in a map..
If Key1 .. i should retrieve Value1...
If Key2 .. i should retrieve Value2...
How do i code this...???????
"Ulrich Eckhardt" wrote:
Alamelu wrote:.
can we define a const map , which will take both key and value also to be^^^^^ 1 ^^^^^ 2 ^^^^^ 3
constants?
something like this...........
const std::map< const unsigned char,const unsigned char> sample_map;
There are three const there. The first, just makes the map a constant, i.e.
you can't insert or delete elements etc. This also affects the contained
values, you can only get const references to them.
The second is the key type and even value_type of std::map is already
pair<key_type const, data_type>. I think you can use a constant as
key_type, at least the SGI docs don't mention any restrictions like the
mention on the data_type.
The third type is a const on the data_type, which won't work because those
need to be assignable.
FYI, the (otherwise not relevant) documentation for the STL from SGI's
website explains which types have to fulfil which requirement, you might
want to take a look at them. I guess the docs at the MSDN do the same.
In that case how to we populate it????????
The only const that works and does anything relevant is the first, which
means that you have a const map. You can only populate this via
initialisation, i.e. one of the constructors.
BTW: if you want to solve a real problem, you might want to tell us about
that instead of asking for some cornercase solution.
cheers
Uli
- References:
- Re: Maps
- From: Ulrich Eckhardt
- Re: Maps
- Prev by Date: Re: Error C2535 With vector ("member function already defined")
- Next by Date: Re: Maps
- Previous by thread: Re: Maps
- Next by thread: Re: Maps
- Index(es):
Relevant Pages
|