cpp摆锤图形程序编译错误



在尝试用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++ CodeTest.cpp  [Error] 'int y1' redeclared as different kind of symbol
1   0   C++ CodeTest.cpp  In file included from Test.cpp
266 24  Dev-CppMinGW64x86_64-w64-mingw32includemath.h  [Note] previous declaration 'double y1(double)'
C++ CodeTest.cpp  In function 'void display(double)':
15  23  C++ CodeTest.cpp  [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
16  23  C++ CodeTest.cpp  [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
17  23  C++ CodeTest.cpp  [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
18  23  C++ CodeTest.cpp  [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
26  15  C++ CodeTest.cpp  [Error] invalid operands of types 'double(double)' and 'double' to binary 'operator+'
27  16  C++ CodeTest.cpp  [Error] invalid conversion from 'double (*)(double)' to 'int' [-fpermissive]
6   0   C++ CodeTest.cpp  In file included from Test.cpp
212 6   Dev-CppMinGW64x86_64-w64-mingw32includegraphics.h  [Note] initializing argument 2 of 'void line(int, int, int, int)'
C++ CodeTest.cpp  In function 'int main()':
37  33  C++ CodeTest.cpp  [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
28      C++ CodeMakefile.win  recipe for target 'Test.o' failed

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

换个名字吧。

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

最新更新