Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

name lookup of 'iter' changed for new ISO 'for' scoping

Tags:

c++

I'm trying to compile the two files below, but get an error message from the compiler: gcc 4.3.3 (Linux)

The error is in the line signed with: LINE WITH ERROR

What I'm I doing wrong, how should I change it?

Luis ...............................

$ g++ -c b.h b.cpp 
b.cpp: In function 'void calcularDesempPop(std::vector<Individuo, std::allocator<Individuo> >&)':
b.cpp:19: error: name lookup of 'iter' changed for new ISO 'for' scoping
b.cpp:17: error:   using obsolete binding at 'iter'

............................... FILE: b.cpp

#include <iostream>
#include <algorithm>
#include "desempenho.h"

using std::cout;
using std::endl;

struct Individuo {
    vector<double> vec;
    double desempenho;
};



void calcularDesempPop(vector<Individuo>& pop) {
    for (vector<Individuo>::iterator iter = pop.begin();
                    iter != pop.end(); ++iter);//LINE WITH ERROR
        iter->desempenho = calcularDesempenho(iter->vec);
        cout << endl;
}

............................... FILE: b.h

#ifndef GUARD_populacao_h
#define GUARD_populacao_h

//#include <algorithm>
#include <iostream>
#include "cromossoma.h"

struct Individuo {
    vector<double> vec;
    double desempenho;
};


void calcularDesempPop(vector<Individuo>& pop);

#endif
like image 881
Luis Avatar asked Nov 29 '22 18:11

Luis


1 Answers

$6.5.3/3 - "If the for-init-statement is a declaration, the scope of the name(s) declared extends to the end of the for statement."

Therefore iter cannot be accessed outside the for loop scope. Check the semicolon immediately after the for loop. Most probably you did not intend it that way.

like image 200
Chubsdad Avatar answered Dec 14 '22 21:12

Chubsdad