0

Hi,

I dont know much about programming, however I have a c++ program(i didnt write it) that I need to use it to do some experiments. When I compile the program I get this errror.

dynn.cpp: In function ‘void make_near()’:
dynn.cpp:374: error: name lookup of ‘j’ changed for new ISO ‘for’ scoping
dynn.cpp:370: error:   using obsolete binding at ‘j’

Could you help me to fix this please? As I mentioned before i dont know much about programming.So I would appreciate it if you can guide me in the simplest way as possible. Thank you.

dynn.cpp

void make_near()
{
	int real_input;
	int real_hidden;
	
	real_input = xnow.m_input + xnow.m_input*(xnow.m_input+1)/2;
	real_hidden = 2 * real_input;	
	int alter = (real_input + 2) * real_hidden + 1;
	int length1 = (real_input + 1) * real_hidden;
	int length2 = real_hidden + 1;
	alter = alter / 10 + 1;
	int p;
	int p1;
	int p2;
    for(int i=0;i<NO_OF_POPU;i++)
	{
		for(int j=0;j<(real_input + 1) * real_hidden;j++)
		{
			xnear[i].m_weights1[j] = xnow.m_weights1[j];
		}
		for(j=0;j<real_hidden+1;j++)
		{
			xnear[i].m_weights2[j] = xnow.m_weights2[j];
		}
		for(int k=0;k<alter;k++)
		{
            p = (int)(rand() % 2);
			if(p == 0)
			{
				p1 = (int)(rand() % length1);
				xnear[i].m_weights1[p1] += produce_rand_double(-1./LENGTH,1./LENGTH);
			}
			if(p == 1)
			{
				p2 = (int)(rand() % length2);
				xnear[i].m_weights2[p2] += produce_rand_double(-1./LENGTH,1./LENGTH);
			}
		}
		xnear[i].m_fitness = count_nn_fitness(xnear[i]);
	}
}
2
Contributors
2
Replies
9
Views
8 Years
Discussion Span
Last Post by BoneXXX
0

At line 17 of the code you posted the variable j is only visible in that for loop. If you want to use that variable again on line 21 it will have to be declared again just like it was on line 17. Another way to fix the problem is to declare that variable on line 14 similar to the way those other integers were declared, then remove the declaration on line 17 to make line 17 similar to line 21.

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.