Posted by Fox on 2000-07-06
The following is a code snip of a program. 'population' is a CList, and that's all
you really need to be concerned with at the moment. The problem happens on
the lines marked with <---
void CDrawWnd::OnTimer(UINT nIDEvent)
{
int deathtest = NIL;
int ListLimit = 0;
int subListLimit = 0;
POSITION place;
POSITION place2;
POSITION ToKill[10];
int LastToDie = 0;
//STEP ONE:: PROCESS FACADES NORMALLY
if(population.IsEmpty())
{
for(int i = 0; i < 5; i++)
AddFacade(i);
}
place = population.GetHeadPosition();
place2 = population.GetHeadPosition();
Facade &currFacade = population.GetAt(place);<---
Facade &currSubFacade = population.GetNext(place2);<--- FOR BOTH OF
THESE LINES, THE OVERLOADED OPERATOR (=) INSIDE class Facade ISN'T
CALLED.
LastToDie = -1;
for(ListLimit = 0; ListLimit < population.GetCount(); ListLimit++)
{
currFacade.EraseFacade();
currFacade.AddEnergy();
if(currFacade.UseEnergy() == FACADE_DYING)
{
if(LastToDie < 10)
{
if(LastToDie == -1)
LastToDie = 0;
ToKill[LastToDie] = place;
LastToDie++;
}
}
for(subListLimit = 0; subListLimit < population.GetCount(); subListLimit++)
{
(currFacade & currSubFacade);//intersection test
currSubFacade = population.GetNext(place2);<--- BUT HERE, THE
OPERATOR OVERLOAD FOR = IS CALLED! WHY?
}
currFacade.MoveFacade();
currFacade.Drawing();
currFacade = population.GetNext(place);<--- = OVERLOAD IN THAT CLASS
IS CALLED.
}
I don't see why the overloaded version of the operator isn't called at the
initialization, but is everywhere else! Because of this, I'm sure it's the cause of
the runtime errors I'm getting, which happen inside the = overload at the marked
lines within those big loops.
But if I understand reference variables (what GetAt() and GetNext() return),
they're just like pointers, only more transparent. This tells me the overload of
operator = shouldn't need to be called! It isn't at the initialazation, so why is it
everywhere else?
I need to keep this working right. I could use a whole lot of
population.GetAt(place);'s, but that's soooo slow. Any ideas?? Should you need
further clarafication, drop me a note. Becuase this code is of a private nature, I
hesitate giving it out too much.
Previous post | Next post | Timeline | Home