N
nrivera.eng
Gurus,
This is the problem:
The code below outputs bogus data when the either: *( iter->second )
is used and causes a segfault or *(tools[iter->first]) is used the
curious things is that the output of iter->first is perfect and when
the input is verified by:
for(int i = 0 ; inventory && !inventory.eof(); i++ )
{
Tool tempTool;
inventory >> tempTool;
tools.insert( Record::value_type( tempTool.getRecordNum(),
&tempTool ) );
cout << *(tools[tempTool.getRecordNum()]); // Input verification
}
The data seems to be correctly input into the Map data structure so
WHY THE BOGUS OUTPUT and the SEGFAULT?
Here is the Output portion:
for( Record::const_iterator iter = tools.begin(); iter !=
tools.end();
++iter)
{
cout << *(tools[iter->first])<< endl;
}
were Record is:
typedef map < int, Tool *, less< int > > Record;
and Tools is a ( int, string, int, double ) object
the << operator has been overloaded and verified.
Thanks,
Noel
This is the problem:
The code below outputs bogus data when the either: *( iter->second )
is used and causes a segfault or *(tools[iter->first]) is used the
curious things is that the output of iter->first is perfect and when
the input is verified by:
for(int i = 0 ; inventory && !inventory.eof(); i++ )
{
Tool tempTool;
inventory >> tempTool;
tools.insert( Record::value_type( tempTool.getRecordNum(),
&tempTool ) );
cout << *(tools[tempTool.getRecordNum()]); // Input verification
}
The data seems to be correctly input into the Map data structure so
WHY THE BOGUS OUTPUT and the SEGFAULT?
Here is the Output portion:
for( Record::const_iterator iter = tools.begin(); iter !=
tools.end();
++iter)
{
cout << *(tools[iter->first])<< endl;
}
were Record is:
typedef map < int, Tool *, less< int > > Record;
and Tools is a ( int, string, int, double ) object
the << operator has been overloaded and verified.
Thanks,
Noel