Re: CArray of stdext::hash_map<int,int> not possible ( access violation ) ?
CArray memcpys its elements and is therefore incompatible with non-PODs (POD
= Plain Old Data) such as all STL containers. This particular code doesn't
crash with VC10, but a trivial modification does crash:
C:\Temp>type meow.cpp
#include <afxtempl.h>
#include <hash_map>
int main() {
typedef stdext::hash_map<int, int> MAP;
CArray<MAP> test;
MAP item;
test.Add(item);
test.Add(item);
test[0][111] = 222;
test[0][333] = 444;
test[1][555] = 666;
test[1][777] = 888;
test.RemoveAll();
}
C:\Temp>cl /EHsc /nologo /W4 /MTd meow.cpp
meow.cpp
_WIN32_WINNT not defined. Defaulting to _WIN32_WINNT_MAXVER (see
WinSDKVer.h)
C:\Temp>meow
[BOOM]
Please don't modify _ITERATOR_DEBUG_LEVEL (formerly
_HAS_ITERATOR_DEBUGGING/_SECURE_SCL) without knowing exactly what you're
doing. That's like silencing compiler warnings without understanding them.
Because the STL works with non-PODs, STL containers can hold ATL/MFC
objects. (They just need to be copyable and assignable - only overloaded
op&() presents problems.)
(CArray also has a terrible growth policy.)
Stephan T. Lavavej
Visual C++ Libraries Developer
"Giovanni Dicanio" <giovanniDOTdicanio@REMOVEMEgmail.com> wrote in message
news:e$9NudHwKHA.3952@TK2MSFTNGP06.phx.gbl...
"Giovanni Dicanio" <giovanniDOTdicanio@REMOVEMEgmail.com> ha scritto nel
messaggio news:#$kXYmGwKHA.5940@TK2MSFTNGP02.phx.gbl...
I'll let you know if I have some more information...
A small update: I've just tried in VS2010 RC, and the code runs fine (no
access violation).
Giovanni