>> buffer[field.Size()] = 0;
this C string technique is unnecessary when using std::string objects (assuming buffer is std::string). And it might actually cause data corruption if the amount of allocated space is not enough for that character.
>> if ( code = "SUB1" )
you probably intend to use the boolean operator ==, not the assignment operator.
I don't know if the following will answer your question, but this is another way to code that function. You really should get rid of those global variables and use class properties instead. That way you can get a separate set of those structures for every instance of SubjectData class.
void SubjectData::processMessage(
const bha::sessionLayer::SubjectData& event, TibMsg& msg) {
subject* sptr = 0;
if (msg.Get("CODE1", field) == TIBMSG_OK) {
field.Convert(buffer, TIB_BUFFER_SIZE);
buffer[field.Size()] = 0;
code = buffer;
if(code == "SUB1")
sptr = &level1;
else if(code == "SUB2")
sptr = &level2;
else if(code == "SUB3")
sptr = &level3;
else
sptr = 0; // error
found = true;
}
<snip>
if (found == true && sptr != 0)
{
sptr->data1 = data1;
sptr->data2 = data2;
sptr->data3 = data3;
} Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343