【发布时间】:2016-06-14 17:09:05
【问题描述】:
我正在尝试使用基类“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:错误:“区域”没有命名类型
【问题讨论】:
-
把这些东西放在构造函数或其他什么...你知道构造函数是什么吗?你没有使用它们。
-
@LogicStuff 你能帮我弄清楚吗?
-
这里是构造函数上的tutorial 的链接。以及inheritance 上的另一个链接。阅读它们; Google 是您的朋友。
-
另外,你的
main()函数什么也没做。要么摆脱它,要么用它来展示你的问题。
标签: c++ class inheritance void