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
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.