【发布时间】:2016-10-14 10:34:26
【问题描述】:
好的,我编辑我的代码,我想做的很简单,我有一个带有坐标(x,y)的大形状。我想要做的是调整我的原始形状的大小,将它存储在一个名为“new”的类中的新图形中,并将这个新形状移动到我想要的坐标(x,y)。
// Example program
#include <iostream>
#include <string>
// Base class Shape
class Shape
{
public:
Shape(int inwidth, int inheight): width(inwidth), height(inheight){
}
void ResizeW(int w)
{
width = w;
}
void ResizeH(int h)
{
height = h;
}
void moveF(int x_delta, int y_delta)
{
x1 = x_delta;
y1 = y_delta;
x2 = x_delta;
y2 = y_delta;
}
protected:
int x1=0, y1=0, x2=5, y2=6;
int width;
int height;
};
// Primitive Shapes
class Ps2: public Shape
{
public:
Ps2 (int width, int height): Shape(width, height){
}
int getArea()
{
return (width * height);
}
};
// Derived Shapes
class New: public Ps2
{
int x1_relativ, y1_relativ, x2_relativ, y2_relativ;
public:
int area;
New(): Ps2(8, 4), area(getArea()){ }
};
int main(void)
{
New kit;
moveF.kit (4, 3, 5, 7);
std::cout << "Total area: " << kit.getArea();
std::cout << "Cordinates are: " << kit.moveF();
return 0;
}
现在我有四个错误:在函数“int main()”中: 66:6:错误:未在此范围内声明“moveF” 68:51:错误:没有匹配的函数调用'New::moveF()' 68:51:注:候选人是: 21:11:注意:void Shape::moveF(int, int) 21:11:注意:候选人期望 2 个参数,提供 0 个。 另外我认为我无法使用“move.f”我创建了任何帮助?
【问题讨论】:
-
您的问题不太清楚,能否详细说明您需要什么?
-
@shrike 我画了一个草图。它可以提供帮助
-
也许您想创建一个
Shape类,然后从中派生类(如Square和Ell)。是这个意思吗? -
@Beta 有点像!但是假设我要派生的类是由 Square 和 Ell 的几何变换组成的形状,并且必须放在我的 Shape 类中,我该怎么办?
-
也许你有一个新用户名 - 因为这是同一主题 stackoverflow.com/questions/37599215/inheritance-classes/…
标签: c++ class coordinates overlap area