invalid conversion from ‘double (*)(double) throw ()’ to ‘int’ 问题解决

原因:y1是一个c++源码里的一种double类型的变量
解决方法:不用y1变量 改个名字就行了
invalid conversion from ‘double (*)(double) throw ()’ to ‘int’ 问题解决_第1张图片
报错

Main.cc:9:8: error: ‘int y1’ redeclared as different kind of symbol
 int x1,y1,x2,y2;
        ^
In file included from /usr/include/features.h:367:0,
                 from /usr/include/x86_64-linux-gnu/c++/5/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/5/bits/c++config.h:482,
                 from /usr/include/c++/5/iostream:38,
                 from Main.cc:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:251:1: note: previous declaration ‘double y1(double)’
 __MATHCALL (y1,, (_Mdouble_));
 ^
Main.cc: In function ‘int main()’:
Main.cc:20:42: warning: format ‘%d’ expects argument of type ‘int*’, but argument 3 has type ‘double (*)(double) throw ()’ [-Wformat=]
     while(scanf("%c%d %c%d",&a,&y1,&b,&y2)!=EOF){
                                          ^
Main.cc:21:39: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘double (*)(double) throw ()’ [-Wformat=]
         printf("%c%d->%c%d:",a,y1,b,y2);
                                       ^
Main.cc: In function ‘void bfs()’:
Main.cc:32:8: error: invalid conversion from ‘double (*)(double) throw ()’ to ‘int’ [-fpermissive]
     o.y=y1;
        ^

我的代码

#include
#include
#include
#include
#include
#include
using namespace std;
char a,b;
int x1,y1,x2,y2;
int go[8][2]={2,1,2,-1,1,2,1,-2,-2,1,-2,-1,-1,-2,-1,2};
int visited[10][10]={0};
struct node{
    int x;
    int y;
    int step;
};
void bfs();
 
int main(){
    while(scanf("%c%d %c%d",&a,&y1,&b,&y2)!=EOF){
        printf("%c%d->%c%d:",a,y1,b,y2);
        x1=a-'a'+1;
        x2=b-'a'+1;
        memset(visited,0,sizeof(visited));
        bfs();
    }
}
void bfs(){
    queue q;
    node o,n;
    o.x=x1;
    o.y=y1;
    o.step=0;
    visited[o.x][o.y]=true;
    q.push(o);
    while(!q.empty()){
        o=q.front();
        q.pop();
        if(o.x==x2 && o.y==y2){
            cout<=1 && n.x<=8 && n.y>=1 && n.y<=8 && !visited[n.x][n.y]){
                n.step++;
                visited[n.x][n.y]=true;
                q.push(n);
            }
        }
    }
}

你可能感兴趣的:(折腾)