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]);
	}
}

Recommended Answers

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 …

Jump to Post

All 2 Replies

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.

Thank you very much, problem is fixed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.