码迷,mamicode.com
首页 > 其他好文 > 详细

name lookup of 'res' changed for new ISO(转)

时间:2014-08-13 22:02:07      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:style   color   使用   for   ar   问题   div   linux   

 
 
 
{
int exp = 10;
cout << pow ( val, exp ) << endl;
 
{
for ( int res=1 ; exp > 0; exp-- )
return res;
在linux下用g++编译会出现如下错误:
error: name lookup of ‘res’ changed for ISO ‘for’ scoping
note: (if you use ‘-fpermissive’ G++ will accept your code)
它说的是 for 循环中在 “初始化”部分 定义的变量的作用域范围的一个问题。ISO/ANSI C++ 把在此定义的变量的作用域范围限定在 for 循环体 内,或者说,出了循环体之外这个变量就无效了。可以使用‘-fpermissive’使编译通过。
应该把红色部分改成:
int  res;
for ( res=1 ; exp > 0; exp-- )

name lookup of 'res' changed for new ISO(转),布布扣,bubuko.com

name lookup of 'res' changed for new ISO(转)

标签:style   color   使用   for   ar   问题   div   linux   

原文地址:http://www.cnblogs.com/bofengyu/p/3910893.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!