初学C++,遇到一个很简单的问题,你们一定要帮帮我啊,在线等

zhongxiaoying 2003-09-29 05:58:02
//以下是一个构造圆,矩形,椭圆的程序,分别移动,显示他们,望高手们能指点一下,不胜感激

//以下是出现的一些错误:--------------------Configuration: yuan - Win32 Debug--------------------
Compiling...
main.cpp
c:\program files\microsoft visual studio\myprojects\z1\yuan\figures.h(36) : error C2614: 'point' : illegal member initialization: 'location' is not a base or member
c:\program files\microsoft visual studio\myprojects\z1\yuan\figures.h(126) : warning C4518: 'int ' : storage-class or type specifier(s) unexpected here; ignored
c:\program files\microsoft visual studio\myprojects\z1\yuan\figures.h(126) : warning C4228: nonstandard extension used : qualifiers after comma in declarator list are ignored
c:\program files\microsoft visual studio\myprojects\z1\yuan\figures.h(128) : error C2969: syntax error : ';' : expected member function definition to end with '}'
c:\program files\microsoft visual studio\myprojects\z1\yuan\figures.h(129) : error C2059: syntax error : '{'
c:\program files\microsoft visual studio\myprojects\z1\yuan\figures.h(129) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
c:\program files\microsoft visual studio\myprojects\z1\yuan\main.cpp(8) : error C2065: 'drag' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\z1\yuan\main.cpp(11) : warning C4508: 'main' : function should return a value; 'void' return type assumed
Error executing cl.exe.

main.obj - 5 error(s), 3 warning(s)




//figures.h

#include<stdio.h>
#include<conio.h>

class location{

protected:
int m;
int n;
public:
location(int intm,int intn)
{
m=intm;
n=intn;
}

int getm()
{
return(m);

}

int getn()
{
return(n);
}
};


class point{
protected:
int x,y;
bool visible;
public:
point(int initx,int inity):location(initx, inity)
{

visible=false;
}
int getx(void)
{
return(x);
}
int gety(void)
{
return(y);
}
virtual void show()
{
visible=true;
printf("移动到%d,%d位置\n",x,y);
}

virtual void hide()
{
visible=false;
printf("%d,%d位置擦除点\n",x,y);
};
void meveto (int newx,int newy)
{
hide();
x=newx;
y=newy;
show();
}
};

class Rectangle:public point
{
protected:
int height,width;
public:
Rectangle(int a,int b,int c,int d):point(a,b)
{
height=c;
width=d;
}
int getheight(void)
{
return(height);
}
int getwidth(void)
{
return(width);
}
void show()
{
visible=true;
printf("%d,%d位置显示height为%d,width为%d的矩形\n",x,y,height,width);
}
void hide()
{
visible=false;
printf("%d,%d位置擦除height为%d,width为%d的矩形\n",x,y,height,width);
}
};
class Circle : public point
{
protected:
int radius;
public:
Circle(int i,int j,int r):point(i,j)
{
radius =r;
}
int getr(void)
{
return(radius);
}
void show()
{
visible=true;
printf("%d,%d位置显示半径为%d的圆\n",x,y,radius);
}
void hide()
{
visible=false;
printf("%d,%d位置擦除半径为%d的圆\n",x,y,radius);
}


};

class Clipse : public location{
private:
int l1,int l2;
public:
Clipse(int i,int j,int k,int l):location(i,j);
{
l1=k;l2=l;
}
int getl1(void)
{
return(l1);
}
int getl2(void)
{
return(l2);
}
};


//main.cpp

bool getdelta(int &deltax,int &deltay)//通用函数,获得拖动方向
{
unsigned char keychar;
bool quit;
deltax=0;
deltay=0;
do
{
keychar=getch();
if(keychar()==1)
return(false);
quit=true;
switch(keychar)
{
case 72:deltay=-1;break;
case 80:deltay=1;break;
case 75: deltax=-1;break;
case 77:deltax=1;break;
default:quit=false;
}
}while(!quit)

return(true);
}


void drag(point &anyfigure,int dragby)//通用函数,拖动任意图形
{
int deltax,deltay;
int figurex,figurey;
anyfigure.show();
figurex=anyfigure.getx();
figurey=anyfigure.gety();
while(getdelta(deltax,deltay))
{
figurex+=deltax*dragby;
figurey+=deltay*dragby;
anyfigure.moveto(figurex,figurey);
}
}


#include"figures.h"

main()
{
Circle ac(200,100,50);
Rectangle ar(100,100,200,100);
Clipse ad(200,200,300,300);
drag(ac,5);
drag(ar,10);
drag(ad,15);
}








...全文
218 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
playboyxp 2003-09-29
  • 打赏
  • 举报
回复
错误严重
zhongxiaoying 2003-09-29
  • 打赏
  • 举报
回复
我发现已经调试出来了
只是我操作有问题,谢谢你拉
我给你加分了!
yuefeng521521521 2003-09-29
  • 打赏
  • 举报
回复
没有哪个文件?能不能把错误说的详细些?
我这里调试都通过了。

你用的什么编译器?
zhongxiaoying 2003-09-29
  • 打赏
  • 举报
回复
我把我已经改好了的程序给你吧,现在只有一个错误了,就是运行到 anyfigure.show();时候会跳出来,说没有那个文件,我不明白为什么,错误已经在下面标出来了





//main.cpp
#include<stdio.h>
#include"figures.h"
#include<conio.h>

bool getdelta(int &deltax,int &deltay)
{
unsigned char keychar;
bool quit;
deltax=0;
deltay=0;
do
{
keychar=getch();
if(keychar==1)
return(false);
quit=true;
switch(keychar)
{
case 72:deltay=-1;break;
case 80:deltay=1;break;
case 75: deltax=-1;break;
case 77:deltax=1;break;
default:quit=false;
}
}while(!quit);

return(true);
}
void drag(point &anyfigure,int dragby)
{
int deltax,deltay;
int figurex,figurey;
anyfigure.show();//运行到这里自动退出,说找不到文件,不知道为什么
figurex=anyfigure.getx();
figurey=anyfigure.gety();
while(getdelta(deltax,deltay))
{
figurex+=deltax*dragby;
figurey+=deltay*dragby;
anyfigure.meveto(figurex,figurey);
}
}
yuefeng521521521 2003-09-29
  • 打赏
  • 举报
回复
9、把location中的m都改为x,把n都改为y

class location{

protected:
int x;
int y;
public:
location(int intx,int inty)
{
x=intx;
y=inty;
}

int getx()
{
return(x);

}

int gety()
{
return(y);
}
};

10、把point类中:
// int x,y; //注释掉

zhongxiaoying 2003-09-29
  • 打赏
  • 举报
回复
帮帮啊
zhongxiaoying 2003-09-29
  • 打赏
  • 举报
回复
现在连上面那个问题也解决了.但是结果却不正确,你能帮我调试一下吗?
yuefeng521521521 2003-09-29
  • 打赏
  • 举报
回复
8、main()中
Clipse ad(200,200,300,300);
drag(ad,15); //出错。因为ad不是point对象,因此调用
//void drag(point &anyfigure,int dragby)会出错
zhongxiaoying 2003-09-29
  • 打赏
  • 举报
回复
上面的问题解决了,遇到了这样一个问题,



void main()
{
Circle ac(200,100,50);
Rectangle ar(100,100,200,100);
Clipse ad(200,200,300,300);
drag(ac,5);
drag(ar,10);
drag(ad,15);//这一行有问题
}


C:\Program Files\Microsoft Visual Studio\MyProjects\Z1\yuan\main.cpp(50) : error C2664: 'drag' : cannot convert parameter 1 from 'class Clipse' to 'class point &'
yuefeng521521521 2003-09-29
  • 打赏
  • 举报
回复
4、main.cpp的getdelta中
if(keychar()==1)
改为:
if(keychar==1) //去掉括号

5、main.cpp的getdelta中
}while(!quit)
改为:
}while(!quit); //加上分号

6、Point类中
void meveto (int newx,int newy)
改为:
void moveto (int newx,int newy) //写错了一个字母

7、main函数
main()
该为:
void main()
zhongxiaoying 2003-09-29
  • 打赏
  • 举报
回复
很感谢您,还有一个错误;c:\program files\microsoft visual studio\myprojects\z1\yuan\main.cpp(8) : error C2065: 'drag' : undeclared identifier
请帮帮我?
yuefeng521521521 2003-09-29
  • 打赏
  • 举报
回复
3、Clipse类中:
Clipse(int i,int j,int k,int l):location(i,j);
应改为:
Clipse(int i,int j,int k,int l):location(i,j) //去掉分号
yuefeng521521521 2003-09-29
  • 打赏
  • 举报
回复
2、Clipse类中:
int l1,int l2;
应写为:
int l1,l2;
或者
int l1;
int l2;
yuefeng521521521 2003-09-29
  • 打赏
  • 举报
回复
1、你的point类是继承自location类,要写为:
class point:public location
{
//......
}
之后才可以在point类的构造函数中调用基类location类的构造函数
point(int initx,int inity):location(initx, inity)

64,281

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧