MAP ITERATOR ISSUES

Hi all, this code is working on VS2005 but not on LINUX.

.h
1
2
3
4
5
6
7
8
9
#include <map>
typedef struct 
{  
  int		MsgSeqNum;
  string	Symbol;
} INSTRUMENT;
	
typedef map<int,INSTRUMENT*> MAP_INSTRUMENTS;
MAP_INSTRUMENTS          _mapInstruments;

.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
printf("Display _mapInstruments.size() %d\n", _mapInstruments.size());
MAP_INSTRUMENTS::iterator it;
for(it = _mapInstruments.begin(); it != _mapInstruments.end(); it++)
{
    //Problem here : VS2005 will never come inside for-loop when the _mapInstruments.size() = 0(nothing inside)
    //But in Linux it will always come inside this loop, then it crash because it->second is bad pointer?    

    printf("check it->second %x\n", (*it).second);
    if ((*it).second)
   {
        printf("Display it->second %x\n", (*it).second);
        if (((*it).second->Symbol) == asymbol)
        {
	afound true;
	break;
        }
    }
}


What's wrong with my code?
Thanks.

Last edited on
closed account (S6k9GNh0)
if ((it->second->Symbol) == asymbol)

to

if ( (*it).second->Symbol) == asymbol)

Hopefully that works. If not post again, if so, mark topic complete.
Last edited on
Thanks. I edit the source above again and the result same as below: aborted

1
2
3
4
5
Display _mapInstruments.size() 0
check it->second 0
check it->second 7f26ac0
Display it->second 7f26ac0
Aborted


if (((*it).second->Symbol) == asymbol) cause the aborted? i cannot catch the exception.

Case CLosed : Found the Object is failed b4 tis. tq
Last edited on
Topic archived. No new replies allowed.