Visualizzazione dei risultati da 1 a 4 su 4

Discussione: [c++ stl]map

  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826

    [c++ stl]map

    Ho dichiarato una mappa come variabile membro:
    std::map<int, int> m_mapIndexAlrVisited;
    e poi assegnando un valore alla mappa cosi:
    codice:
    if(m_mapIndexAlrVisited.find(IndexFace.nVertex)!=m_mapIndexAlrVisited.end() )
    			{				
    				NewPos = m_positions.size() + nOffset;
    				nOffset++;
    				aiIndex[NewPos] = NewPos;
    				FillPVertex(IndexFace.nVertex, IndexFace.nNormal, IndexFace.nText, IndexFace.nTang, NewPos);
    				index--;		
    			}
    			else
    			{
    				aiIndex[index] = index;
    				m_mapIndexAlrVisited[index] = 1;
    				FillPVertex(IndexFace.nVertex, IndexFace.nNormal, IndexFace.nText, IndexFace.nTang, index);
    				
    }
    lavora bene da 0 a 6, poi quando tento di inserire all'indice 7 il valore 1
    m_mapIndexAlrVisited[index] = 1;
    mi da quest'errore:
    Unhandled exception at 0x755ee124 in MaterialTextures_VC90WglDebSta.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0017e0dc..

    e mi apre per debuggare il file mlock.c.

    non riesco a capire perchè.
    grazie.

  2. #2
    Solitamente questo genere di errore si ottiene quando non c'è sufficiente memoria, ma vedendo solo quel pezzo di codice è difficile dire qualcosa... per inciso, mi sembra che tu stia usando la mappa in questione come un array più che come un container associativo, se è così forse ti conviene usare std::vector.
    Amaro C++, il gusto pieno dell'undefined behavior.

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826
    grazie Mitaly.
    Ho provato a togliere la mappa come variabile membro perchè in effetti basta che sia interna alla funzione,Il problema è che uso una mappa perchè nel confronto:
    mapIndexArlVisited.find(IndexFace.nVertex)!=mapInd exArlVisited.end()
    in IndexFace.nVertex ci possono essere numeri non sequenziali , come 0,6,4,2,7 ecc... e io devo testare che non ci siano gia.
    ma anche cosi , l'errore è lo stesso !

    ps.
    Ho provato a compilare con multithread debug anziche multithread debug dll e il linker mi da un casino di errori , del tipo :
    1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: char const * __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::c_str(void)const " (?c_str@?$basic_string@DU?$char_traits@D@std@@V?$a llocator@D@2@@std@@QBEPBDXZ) already defined in ColladaReaderTriangles.obj
    1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "bool __cdecl std:perator==<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??$?8DU?$char_traits@D@std@@V?$allocator@D@1@@std @@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$ allocator@D@2@@0@0@Z) already defined in ColladaReaderTriangles.obj
    1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$alloc ator@D@2@@std@@QAE@XZ) already defined in ColladaReaderTriangles.obj
    1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *)" (??0?$basic_string@DU?$char_traits@D@std@@V?$alloc ator@D@2@@std@@QAE@PBD@Z) already defined in ColladaReaderTriangles.obj
    1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "void __cdecl std::_Debug_message(wchar_t const *,wchar_t const *,unsigned int)" (?_Debug_message@std@@YAXPB_W0I@Z) already defined in libcpmtd.lib(stdthrow.obj)
    1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QAE@XZ) already defined in libcpmtd.lib(xlock.obj)
    1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::_Lockit::_Lockit(int)" (??0_Lockit@std@@QAE@H@Z) already defined in libcpmtd.lib(xlock.obj)
    1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: void __thiscall std::_Container_base_secure::_Orphan_all(void)cons t " (?_Orphan_all@_Container_base_secure@std@@QBEXXZ) already defined in ColladaReaderTriangles.obj
    1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::_Container_base_secure::~_Container_base_secu re(void)" (??1_Container_base_secure@std@@QAE@XZ) already defined in ColladaReaderTriangles.obj
    1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0?$basic_string@DU?$char_traits@D@std@@V?$alloc ator@D@2@@std@@QAE@ABV01@@Z) already defined in ColladaReaderTriangles.obj
    1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::_Container_base_secure::_Container_base_secur e(void)" (??0_Container_base_secure@std@@QAE@XZ) already defined in ColladaReaderTriangles.obj
    1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >:perator=(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??4?$basic_string@DU?$char_traits@D@std@@V?$alloc ator@D@2@@std@@QAEAAV01@ABV01@@Z) already defined in ColladaReaderTriangles.obj
    1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: char const & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >:perator[](unsigned int)const " (??A?$basic_string@DU?$char_traits@D@std@@V?$alloc ator@D@2@@std@@QBEABDI@Z) already defined in Importer.obj
    1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: unsigned int __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::length(void)const " (?length@?$basic_string@DU?$char_traits@D@std@@V?$ allocator@D@2@@std@@QBEIXZ) already defined in ColladaReaderTriangles.obj
    1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::assign(char const *,unsigned int)" (?assign@?$basic_string@DU?$char_traits@D@std@@V?$ allocator@D@2@@std@@QAEAAV12@PBDI@Z) already defined in ColladaReaderTriangles.obj
    1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "bool __cdecl std:perator<<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??$?MDU?$char_traits@D@std@@V?$allocator@D@1@@std @@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$ allocator@D@2@@0@0@Z) already defined in ColladaReaderTriangles.obj
    1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::substr(unsigned int,unsigned int)const " (?substr@?$basic_string@DU?$char_traits@D@std@@V?$ allocator@D@2@@std@@QBE?AV12@II@Z) already defined in ColladaReaderTriangles.obj
    1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "bool __cdecl std:perator!=<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,char const *)" (??$?9DU?$char_traits@D@std@@V?$allocator@D@1@@std @@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$ allocator@D@2@@0@PBD@Z) already defined in ColladaReaderTriangles.obj
    1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "bool __cdecl std:perator==<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,char const *)" (??$?8DU?$char_traits@D@std@@V?$allocator@D@1@@std @@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$ allocator@D@2@@0@PBD@Z) already defined in ColladaReaderTriangles.obj
    1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: static unsigned int __cdecl std::char_traits<char>::length(char const *)" (?length@?$char_traits@D@std@@SAIPBD@Z) already defined in ColladaReaderTriangles.obj
    1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >:perator=(char const *)" (??4?$basic_string@DU?$char_traits@D@std@@V?$alloc ator@D@2@@std@@QAEAAV01@PBD@Z) already defined in ColladaReaderTriangles.obj
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: __wassert already defined in LIBCMTD.lib(wassert.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _fclose already defined in LIBCMTD.lib(fclose.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _getenv_s already defined in LIBCMTD.lib(getenv.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _memcpy_s already defined in LIBCMTD.lib(memcpy_s.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _vsprintf_s already defined in LIBCMTD.lib(vsnprnc.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _strcpy_s already defined in LIBCMTD.lib(strcpy_s.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _strcat_s already defined in LIBCMTD.lib(strcat_s.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _strncpy_s already defined in LIBCMTD.lib(strncpy_s.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: __invalid_parameter already defined in LIBCMTD.lib(invarg.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: __CrtDbgReportW already defined in LIBCMTD.lib(dbgrptw.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: "public: virtual __thiscall std::exception::~exception(void)" (??1exception@std@@UAE@XZ) already defined in LIBCMTD.lib(stdexcpt.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: "public: __thiscall std::exception::exception(void)" (??0exception@std@@QAE@XZ) already defined in LIBCMTD.lib(stdexcpt.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: "public: __thiscall std::exception::exception(char const * const &)" (??0exception@std@@QAE@ABQBD@Z) already defined in LIBCMTD.lib(stdexcpt.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: "public: __thiscall std::exception::exception(class std::exception const &)" (??0exception@std@@QAE@ABV01@@Z) already defined in LIBCMTD.lib(stdexcpt.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _memmove_s already defined in LIBCMTD.lib(memmove_s.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _strncmp already defined in LIBCMTD.lib(strncmp.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _atoi already defined in LIBCMTD.lib(atox.obj)
    1>MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)
    1>MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info:perator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _isdigit already defined in LIBCMTD.lib(_ctype.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _free already defined in LIBCMTD.lib(dbgfree.obj)
    1>MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _malloc already defined in LIBCMTD.lib(dbgmalloc.obj)
    1>LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
    1>MaterialTextures_VC90WglDebSta.exe : fatal error LNK1169: one or more multiply defined symbols found
    1>Build log was saved at "file://c:\programmazione\wild magic 4\GeometricTools\WildMagic4\SampleGraphics\Materia lTextures\Debug\VC90\BuildLog.htm"
    1>MaterialTextures_VC90 - 44 error(s), 2 warning(s)
    ========== Build: 0 succeeded, 1 failed, 6 up-to-date, 0 skipped ==========

  4. #4
    Occhio che così ad occhio mi sembra che tu stia mischiando più CRT differenti, potrebbe essere quello l'origine del problema.
    Amaro C++, il gusto pieno dell'undefined behavior.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.