const TypedeffedIntPointer not equal to const int *
Posted
by dirk
on Stack Overflow
See other posts from Stack Overflow
or by dirk
Published on 2010-05-06T14:24:37Z
Indexed on
2010/05/06
14:28 UTC
Read the original article
Hit count: 319
c++
I have the following C++ code:
typedef int* IntPtr;
const int* cip = new int;
const IntPtr ctip4 = cip;
I compile this with Visual Studio 2008 and get the following error:
error C2440: 'initializing' : cannot convert from 'const int *' to 'const IntPtr'
Clearly my understanding of typedefs is not what is should be.
The reason I'm asking, I'm storing a pointer type in a STL map. I have a function that returns a const pointer which I would like to use to search in the map (using map::find(const key_type&). Since
const MyType*
and
const map<MyType*, somedata>::key_type
is incompatible, I'm having problems.
Regards Dirk
© Stack Overflow or respective owner