代码如下:
#include
using namespace std;
class Point {
protected:
int x;
int y;
double const r;
public:
Point(int px = 0, int py = 0)
: r(1.5)
{
x = px;
y = py;
}
int GetX() { return x; }
int GetY() { return y; }
void SetX(int px) { x = px; }
void SetY(int py) { x = py; }
virtual void ShowPoint() {
cout << "<" << x << "," << y << ">";
}
};
class SpacePoint :public Point {
private:
int z;
public:
SpacePoint():z(0){
}
SpacePoint(int px, int py, int pz):Point(px,py) {
z = pz;
}
int GetZ() { return z; }
void SetZ(int pz) { z = pz; }
virtual void ShowPoint() {
cout << "<" << x << "," << y << ',' << z << ">" << endl;
}
};
int main()
{
SpacePoint spt(3,4,5);
spt.ShowPoint();
Point pt;
pt=spt;
/*错误在这里,说是行错误 C2280 “Point &Point::operator =(const Point &)”: 尝试引用已删除的函数;行错误(活动) 无法引用 函数 "Point::operator=(const Point &)" (已隐式声明) -- 它是已删除的函数*/
pt.ShowPoint();
Point* p=&spt;
cout << p->GetX() << endl;
Point& rp=spt;
cout << rp.GetX() << endl;
Point*p1 = new SpacePoint(3, 4, 5);
p1->ShowPoint();
cout << endl;
p1 = &spt;
p1->ShowPoint();
cout << endl;
return 0;
}
错误如下: