0

I am confused, I seem to be losing the variable item.Size when i go from one for loop to the next....why?

When i show item.Size the first time it shows all the #s, the second time I get straight 0s?

for (unsigned long int q = 0; q < tableCount; q++)
    {
		for each (AoE2Wide::DrsItem item in inTables[q].Items)
        {
			inFileDrs.read(reinterpret_cast<char*>(&id),sizeof(id));
			inFileDrs.read(reinterpret_cast<char*>(&start),sizeof(start));
			inFileDrs.read(reinterpret_cast<char*>(&size),sizeof(size));
			item.Id = id;
			item.Start = start;
			item.Size = size;
			std::cout << item.Size << std::endl;
        }
    }

//	char *tempItem = new char[1];
//	delete [] tempItem;
    for (unsigned long int q = 0; q < tableCount; q++)
    {
		for each (AoE2Wide::DrsItem item in inTables[q].Items)
        {
			std::cout << item.Size << std::endl;

//			tempItem = new char [item.Size];
//			inFileDrs.read(tempItem, item.Size);
			//item.Data.push_back(*tempItem);
//			for (unsigned long int k = 0; k < item.Size; k++)
//				item.Data.push_back(tempItem[k]);
//			delete [] tempItem;
			//std::cout << item.Data.size() << std::endl;
			/*******************POSSIBLE ERROR ********************/
		}
	}
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by MasterGberry
1

You're not actually modifying the inTables[q].Items in your first loop.

for each (AoE2Wide::DrsItem item in inTables[q].Items)
{
   // item is a copy of what's at inTables[q].Items, modifying item will leave the item in inTables[q].Items in tact
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.