【发布时间】:2016-06-02 18:08:54
【问题描述】:
第一部分
我正在尝试使用基类“SHAPE”中的函数和派生类“RECTANGLE”在我的类“BIGRECTANGLE”中创建一个更大的矩形。我想在课堂上而不是在主课上进行我的侧面变换,我该怎么办?谢谢!
#include <iostream>
using namespace std;
// Base class Shape
class Shape
{
public:
void ResizeW(int w)
{
width = w;
}
void ResizeH(int h)
{
height = h;
}
protected:
int width;
int height;
};
// Primitive Shape
class Rectangle: public Shape
{
public:
int width = 2;
int height = 1;
int getArea()
{
return (width * height);
}
};
// Derived class
class BIGRectangle: public Rectangle
{
public:
int area;
Rectangle.ResizeW(8);
Rectangle.ResizeH(4);
area = Rectangle.getArea();
};
int main(void)
{
return 0;
}
这些是我遇到的错误: - 45:14: 错误: '.' 之前的预期 unqualified-id令牌 - 46:14: 错误: '.' 之前的预期 unqualified-id令牌 - 47:5: 错误:“区域”没有命名类型
【问题讨论】:
-
1. .using std namespace...。 2.将
public Rectangle, public Shape更改为public Rectangle- 矩形已经是一个形状 -
您删除了代码,使我的评论没有任何意义?
-
@EdHeal 但这仍然会给我留下:45:10:错误:'.'之前的预期不合格ID令牌 46:10:错误:“。”之前的预期不合格 ID令牌 47:1:错误:“区域”未命名类型
-
@EdHeal 我正在编辑我的代码
-
请留下代码。也许试试我的改变,告诉我你是怎么过的
标签: c++ class geometry coordinates void