'iter'的名称查找已针对新的ISO'for'范围更改 [英] name lookup of 'iter' changed for new ISO 'for' scoping

查看:393
本文介绍了'iter'的名称查找已针对新的ISO'for'范围更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编译以下两个文件,但从编译器得到一个错误消息:gcc 4.3.3(Linux)

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

错误是在line with:LINE WITH ERROR

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

我该怎么办,我应该怎么改?

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

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

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

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

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


推荐答案


$ 6.5.3 / 3 - 如果for-init语句
是一个声明,则声明的
名称的范围扩展到
的结尾for语句。

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

因此,无法在for循环范围外访问iter。检查for循环之后的分号。很可能你没有这么想。

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.

这篇关于'iter'的名称查找已针对新的ISO'for'范围更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆