Why isn't this variable considered "in scope"?

  • Thread starter Thread starter Tom Padilla
  • Start date Start date
T

Tom Padilla

I am making a map generator and for some bizarre reason I have a variable
that will not come in scope.

Code snippet:

void placeContinents(int NumberOfContinents)
{

for(int Loop = 0; Loop < NumberOfContinents; Loop++)
{
// Get a random X co-ordinate
int ContinentX = (int)((pRND->NextDouble() * _MapWidth) - 0.5);
int ContinentY; // <---------------- ***** It's this one.**********

for(;;)
{
// Get a random Y co-ordinate
int CandidateY = (int)(pRND->NextDouble() * (double)_MapHeight -
(double)0.5);
ContinentY = CandidateY;
double RndNum = pRND->NextDouble();

// Find a tile close enough to the equator...
if(equatorDistance(CandidateY) > (double)0.81999999999999998 +
(double)0.17999999999999999 * RndNum)
break;
}

// ...set a continent marker.
mapGrid->SetValue((char)TileType::GRASS_NORMAL, ContinentX, ContinentY);
}
}

The debugger won't see it and their doesn't appear to be any amount of
declaring I can do to make it show up. I've tried declaring it at the top
of the method, in the first for loop, in the second for loop... I've tried
a while loop I've tried a for(;;) loop...I can't even set breakpoints on it.
When I right click in the IDE and select "Goto Definition" it says it's not
defined, even if I do it to the variable name in the declaration itself!

I cannot, for the life of me get this thing to recognize that variable.

What am I doing wrong?

Thanks,
Tom P.
 
I am making a map generator and for some bizarre reason I have a variable
that will not come in scope.
The debugger won't see it and their doesn't appear to be any amount of
declaring I can do to make it show up.

Tom,

Are you debugging an optimised version of your code?

What you're experiencing is common in optimised builds.

Dave
 
David Lowndes said:
Tom,

Are you debugging an optimised version of your code?

What you're experiencing is common in optimised builds.

Dave

Umm, how do I determine that and how do I make it stop?

I'm coming back to this after a while in C# and it's gotten a little weird.
I was never very good at it and now I have this managed stuff to figure out
too. Thanks for the help.

Tom P.
 
What you're experiencing is common in optimised builds.
Umm, how do I determine that and how do I make it stop?

Project property pages, C++ , Optimization tab.

You're only guaranteed to make sense of things when debugging with the
/Od option.

Dave
 
Back
Top