On Jul 29, 3:59=A0pm, "Jim Langston" <tazmas...@[EMAIL PROTECTED]
> wrote:
> "Andrew Falanga" <af300...@[EMAIL PROTECTED]
> wrote in message
>
> news:f469422e-71fe-49ab-b544-0d0d5ced1151@[EMAIL PROTECTED]
>
>
>
> > 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. =A0It's all
> > using the STL. =A0Below is the text of that message. =A0In it is
contai=
ned
> > some incomplete code that illustrates what I'm trying to do. =A0The
> > compiler is whatever comes with VS 2008.
>
> > I'm trying to make a map in my app like this:
>
> > #define =A0CODE1 =A0 =A00x01
> > #define =A0CODE2 =A0 =A00x02
> > // =A0........
> > #define =A0CODE9 =A0 =A00x09
>
> > #define =A0CODE1_STR =A0 =A0 =A0 =A0 =A0 =A0 =A0"A string for code 1"
> > #define =A0CODE2_STR =A0 =A0 =A0 =A0 =A0 =A0 =A0"A string for code 2"
> > // ....
> > #define =A0CODE9_STR =A0 =A0 =A0 =A0 =A0 =A0 =A0"A string for code 9"
>
> > #include <map>
>
> > std::map <unsigned short int, const char *, less<unsigned short int> >
> > codes;
>
> > codes[CODE1] =3D CODE1_STR;
> > codes[CODE2] =3D CODE2_STR;
> > // .......
> > codes[CODE9] =3D 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> =A0 =A0 =A0 =A0with
> > || 1> =A0 =A0 =A0 =A0[
> > || 1> =A0 =A0 =A0 =A0 =A0 =A0_Kty=3Dunsigned short,
> > || 1> =A0 =A0 =A0 =A0 =A0 =A0_Ty=3Dconst char *,
> > || 1> =A0 =A0 =A0 =A0 =A0 =A0_Pr=3Dstd::less<unsigned short>
> > || 1> =A0 =A0 =A0 =A0]
> > error C2440: 'initializing' : cannot convert from 'const char [16]'
> > to 'int [1008]'
> > || 1> =A0 =A0 =A0 =A0There is no context in which this conversion is
po=
ssible
>
> Strange, compile it and it compiles fine. =A0VC++ Express 2008
>
> Here is the entire program I compiled successfully without any warnings:
>
> #define =A0CODE1 =A0 =A00x01
> #define =A0CODE2 =A0 =A00x02
> #define =A0CODE9 =A0 =A00x09
>
> #define =A0CODE1_STR =A0 =A0 =A0 =A0 =A0 =A0 =A0"A string for code 1"
> #define =A0CODE2_STR =A0 =A0 =A0 =A0 =A0 =A0 =A0"A string for code 2"
> #define =A0CODE9_STR =A0 =A0 =A0 =A0 =A0 =A0 =A0"A string for code 9"
>
> #include <map>
>
> std::map <unsigned short int, const char *, std::less<unsigned short
int>=
>
> codes;
>
> int main()
> {
> =A0 =A0 codes[CODE1] =3D CODE1_STR;
> =A0 =A0 codes[CODE2] =3D CODE2_STR;
> =A0 =A0 codes[CODE9] =3D CODE9_STR;
>
> }
>
> This does not compile for you?
Well, as you might expect, this does compile. Ok, so here's a better
picture of what's happening in my code:
include files:
codes.h // contains only the #defines as mentioned above
impl.h // the implementation of a class library
Source
impl.cpp
<file impl.cpp>
#include "codes.h"
#include "impl.h"
#include <iostream>
#include <map>
// then basically what I have above. I declare the map as spelled out
above
// and then define the map as outlined above.
</file impl.cpp>
I tried to compile the program from the command line just to remove VS
from the equation and I'm still getting those errors. I did, "cl /c /
Foimpl.obj." Oh well, it's tomorrow's fight. I may be posting in
here tomorrow depending on what I find.
Thanks,
Andy


|