注册 登录
编程论坛 C++教室

该程序无法运行,谁能看一下?

cjiang11034 发布于 2009-10-20 17:44, 695 次点击
#include<iostream>
using namespace std;

class circle
{ private:
    int x;
    int y;
    int r;
  public:
     circle(int e,int f,int g);
     void  circle::setcircle(int e,int f,int g)
        {x=e;y=f;r=g;}
     int Getx(){return x;}
     int Gety(){return y;}
     int Getr(){return r;}
     void showcircle();
};
 void circle::showcircle()
  {
    cout<<"横坐标为"<<Getx()<<"纵坐标为"<<Gety()<<"圆的半径为"<<Getr()<<endl;
  }
  
int main()
{ double pi=3.14,s;
  circle BC(5,6,7);
  s=pi*BC.Getr()*BC.Getr();
  
  BC.showcircle();
  cout<<"面积为"<<s;
  system("pause");
  return 0;  
   
}
错误:
  C:\DOCUME~1\administrator\LOCALS~1\Temp\ccCscaaa.o(.text+0x1f2) In function `main':
    [Linker error] undefined reference to `circle::circle(int, int, int)'
     C:\DOCUME~1\administrator\LOCALS~1\Temp\ccCscaaa.o(.text+0x1f2) ld returned 1 exit status
12 回复
#2
小J2009-10-20 19:05
#include<iostream>
using namespace std;
 
class circle
{ private:
    int x;
    int y;
    int r;
  public:
     circle(int e,int f,int g)
     {
         x=e;y=f;r=g;
     }
     int Getx(){return x;}
     int Gety(){return y;}
     int Getr(){return r;}
     void showcircle();  
};
void circle::showcircle()
  {  
    cout<<"横坐标为"<<Getx()<<"纵坐标为"<<Gety()<<"圆的半径为"<<Getr()<<endl;  
  }
   
int main()
{ double pi=3.14,s;
  circle BC(5,6,7);
  s=pi*BC.Getr()*BC.Getr();
   
  BC.showcircle();
  cout<<"面积为"<<s;  
  system("pause");
  return 0;   
   
}
这样就行了
#3
小J2009-10-20 19:06
主要还是错在你的类里面,你的构造函数……
#4
forclwy2009-10-20 19:52
circle(int e,int f,int g);
     void  circle::setcircle(int e,int f,int g)
        {x=e;y=f;r=g;}
这块儿好乱..
#5
cjiang110342009-10-20 20:57
回复 4楼 forclwy
void  circle::setcircle(int e,int f,int g)
        {x=e;y=f;r=g;}
没这个啊!
#6
cjiang110342009-10-20 20:59
回复 4楼 forclwy
不好意思,看错了!的确有这个!
#7
cjiang110342009-10-20 21:01
回复 2楼 小J
还是没啊!出现了新的错误!
`circle::circle(int, int, int)' and `circle::circle(int, int, int)' cannot be overloaded
#8
小J2009-10-20 21:29
我那个在vc6.0上调试通过了啊。你刚才的那个程序是void  circle::setcircle(int e,int f,int g)  
        {x=e;y=f;r=g;}这里写错了。
至于你说的那个新问题是说的我贴上去的程序还是你的原程序?好像我在两个程序中都没发现你说的那两个函数
#9
caolihui10082009-10-21 09:20
没定义构造函数只是做了个声明
#10
cjiang110342009-10-21 12:23
回复 8楼 小J
按你的程序运行的!我用是DEVc++这个软件!没法运行!你用你的编程软件运行出来了吗?
#11
cjiang110342009-10-21 12:23
回复 10楼 cjiang11034
那我的事怎么回事,搞不明白!
#12
cjiang110342009-10-21 12:26
回复 8楼 小J
重新试了一下!能用运行啦!谢啦!
#13
小J2009-10-21 17:24
我用的是vc++6.0,结果完全真确!
1