error: undefined reference to `Circle:Circle()' and `Rectangle:Rectangle()'该怎么处理
error: undefined reference to `Circle::Circle()' and `Rectangle::Rectangle()'
题目如下:
初学渣代码如下:
上面三个class加入主函数后在VC6.0运行正常结果正确,但是在提交到网上系统(soj.me)时出现以下error提示:
求各路大神指正!
另外还有一个问题,关于Class Point中的public下第一行:
多谢!
------解决方案--------------------
1.可能是默认构造函数没给实现。
题目如下:
初学渣代码如下:
#include<iostream>
using namespace std;
class Point
{
protected:
double x,y;
public:
Point();
Point(double x,double y):x(x),y(y){}
Point(Point& pt);
double getx() const {return x;}
double gety() const {return y;}
};
Point::Point(Point& pt)
{
x=pt.x;y=pt.y;
}
class Circle:public Point
{
protected:
int r;
public:
Circle();
Circle(double x,double y, int r):Point(x,y),r(r){}
int getr() const {return r;}
int position(Point &pt);
};
int Circle::position(Point &pt)
{
int ireturn=0;
int temp=0;
int temp0=r*r;
temp = (pt.getx()-x)*(pt.getx()-x)+(pt.gety()-y)*(pt.gety()-y);
if(temp == temp0)
{
ireturn = 0;
}
else if (temp < temp0)
{
ireturn = -1;
}
else
{
ireturn = 1;
}
return ireturn;
}
class Rectangle:public Point
{
protected:
int length,width;
public:
Rectangle();
Rectangle(double x,double y,int length,int width):Point(x,y),length(length),width(width){}
int getlength() const {return length;}
int getwidth() const {return width;}
int position(Point &pt);
};
int Rectangle::position(Point& pt)
{
int ireturn = 0;
if (pt.getx()==x||pt.gety()==y||pt.getx()==x+length||pt.gety()==y+width)
{
ireturn = 0;
}
else if (pt.getx()>x&&pt.getx()<x+length&&pt.gety()>y&&pt.gety()<y+width)
{
ireturn = -1;
}
else
{
ireturn = 1;
}
return ireturn;
}
上面三个class加入主函数后在VC6.0运行正常结果正确,但是在提交到网上系统(soj.me)时出现以下error提示:
求各路大神指正!
另外还有一个问题,关于Class Point中的public下第一行:
class Point那个Point()是什么作用?
{
protected:
double x,y;
public:
Point();
Point(double x,double y):x(x),y(y){}
Point(Point& pt);
double getx() const {return x;}
double gety() const {return y;}
};
多谢!
------解决方案--------------------
1.可能是默认构造函数没给实现。