0

在尝试使用 DevC++ 编译一个简单的图形程序时,我收到以下错误:

#include<math.h>
#include<process.h>
#include<dos.h>
#include<iostream>
#include<conio.h>
#include<graphics.h>
int x1=300,y1=180,x,y;
void display(double i)
{
    circle(300,130,50);
    line(210,60,210,320);
    line(210,60,390,60);
    line(390,60,390,320);
    line(210,320,390,320);
    outtextxy(295,88,"12");
    outtextxy(260,130,"9");
    outtextxy(340,130,"3");
    outtextxy(295,168,"6");
    line(300,130,300,98);
    line(300,98,297,101);
    line(300,98,303,101);
    line(337,130,300,130);
    line(337,130,334,127);
    line(337,130,334,133);
    x=x1+95*cos(i);
    y=y1+95*sin(i);
    line(x1,y1,x,y);
    circle(x,y,10);
    delay(30);
    clearviewport();
}

int main()
{
    int gd=DETECT,gm;
    double i;
    initgraph(&gd,&gm,"C:\\Tc\\BGI");
    while(!kbhit())
    {
        for(i=2;i>1;i=i-0.01)
            display(i);
        for(i=1;i<2;i=i+0.01)
            display(i);
    }
    getch();
    return 0;
    }
7   12  \C++ Code\Test.cpp  [Error] 'int y1' redeclared as different kind of symbol
1   0   \C++ Code\Test.cpp  In file included from Test.cpp
266 24  \Dev-Cpp\MinGW64\x86_64-w64-mingw32\include\math.h  [Note] previous declaration 'double y1(double)'
        \C++ Code\Test.cpp  In function 'void display(double)':
15  23  \C++ Code\Test.cpp  [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
16  23  \C++ Code\Test.cpp  [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
17  23  \C++ Code\Test.cpp  [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
18  23  \C++ Code\Test.cpp  [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
26  15  \C++ Code\Test.cpp  [Error] invalid operands of types 'double(double)' and 'double' to binary 'operator+'
27  16  \C++ Code\Test.cpp  [Error] invalid conversion from 'double (*)(double)' to 'int' [-fpermissive]
6   0   \C++ Code\Test.cpp  In file included from Test.cpp
212 6   \Dev-Cpp\MinGW64\x86_64-w64-mingw32\include\graphics.h  [Note] initializing argument 2 of 'void line(int, int, int, int)'
        \C++ Code\Test.cpp  In function 'int main()':
37  33  \C++ Code\Test.cpp  [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
28      \C++ Code\Makefile.win  recipe for target 'Test.o' failed
4

1 回答 1

1

不幸的是,该名称y1标准库采用,因此您不能将其用作全局变量。

给它另一个名字。

此外,您似乎没有使用 C++ 功能,因此您应该删除#include<iostream>源代码并将其编译为 C,以消除有关char*.

于 2020-09-01T14:11:19.473 回答