Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C - C++ Learning > C++ the STL and...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 9 Topic 4225 of 4370
Post > Topic >>

C++ the STL and std::map

by Andrew Falanga <af300wsm@[EMAIL PROTECTED] > Jul 29, 2008 at 02:46 PM

Hi,

I posted this question to a Windows NG but thought I'd try here
because I can't think of any switch that would be preventing this on
the compiler and there's not MS specific about this code.  It's all
using the STL.  Below is the text of that message.  In it is contained
some incomplete code that illustrates what I'm trying to do.  The
compiler is whatever comes with VS 2008.

I'm trying to make a map in my app like this:

#define  CODE1    0x01
#define  CODE2    0x02
//  ........
#define  CODE9    0x09

#define  CODE1_STR              "A string for code 1"
#define  CODE2_STR              "A string for code 2"
// ....
#define  CODE9_STR              "A string for code 9"

#include <map>

std::map <unsigned short int, const char *, less<unsigned short int> >
codes;

codes[CODE1] = CODE1_STR;
codes[CODE2] = CODE2_STR;
// .......
codes[CODE9] = CODE9_STR;

To which my compiler throws up errors of this "flavor":
 error C2040: 'codes' : 'int [1008]' differs in levels of indirection
from 'std::map<_Kty,_Ty,_Pr>'
|| 1>        with
|| 1>        [
|| 1>            _Kty=unsigned short,
|| 1>            _Ty=const char *,
|| 1>            _Pr=std::less<unsigned short>
|| 1>        ]
 error C2440: 'initializing' : cannot convert from 'const char [16]'
to 'int [1008]'
|| 1>        There is no context in which this conversion is possible

On my Linux machine using gcc (g++ actually) this same code will
compile and run.  Is there some switch to the VS compiler that must be
turned on to use maps and such, similar to the switch for exception
handing (/EHsc)?  It wouldn't seem so, but what could be causing this
problem?

By the way, the reason for the map is that although this example shows
a sequential code numbering, in the app there are several gaps in the
"sequence."  So, I'm using a map rather than an array or vector.

Andy
 




 9 Posts in Topic:
C++ the STL and std::map
Andrew Falanga <af300w  2008-07-29 14:46:21 
Re: C++ the STL and std::map
"Jim Langston"   2008-07-29 14:59:34 
Re: C++ the STL and std::map
Andrew Falanga <af300w  2008-07-29 15:16:08 
Re: C++ the STL and std::map
Ben Bacarisse <ben.use  2008-07-30 00:54:56 
Re: C++ the STL and std::map
Andrew Falanga <af300w  2008-07-30 07:22:31 
Re: C++ the STL and std::map
"Jim Langston"   2008-07-30 07:50:30 
Re: C++ the STL and std::map
Bart van Ingen Schenau &l  2008-07-30 18:01:16 
Re: C++ the STL and std::map
Andrew Falanga <af300w  2008-07-30 07:55:19 
Re: C++ the STL and std::map
"Jim Langston"   2008-07-30 08:01:22 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 13:53:01 CST 2008.