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


|