新的编辑区域和坐标

时间:2016-06-13 21:25:00

标签: c++ class coordinates overlap area

好的我编辑了我的代码,我想做的很简单我有一个很大的形状与corrdinates(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”我创建了任何帮助吗?

1 个答案:

答案 0 :(得分:0)

好吧,编译器会告诉你究竟是什么问题:

moveF.kit(4,3,5,7);

无效代码。你是说kit.moveF吗?另外,为什么四个参数? moveF有两个。

std :: cout&lt;&lt; “Cordinates是:”&lt;&lt; kit.moveF();

有两个错误,首先,moveF需要两个你没有提供的参数,第二个,kit.moveF是一个void,因此不会产生std :: cout可以显示的任何内容。

此外,无法从外部访问您的属性x1,x2,y1,y2。这似乎不是有意的。派生类可以访问它们,但现在没有它可以访问它们。

此外,New是一个可怕的名字。起初困惑我看新工具包;新的显然不是保留的,但如果你知道我的意思,那就感觉很保守。

我的建议是你阅读有关课程和方法的教程。您的理解方法似乎有缺陷。