【发布时间】:2015-04-17 17:34:42
【问题描述】:
我已经嵌套了一个类以在另一个类中使用,并且需要尝试访问它的各个部分但不能。我该怎么做呢?
class Point
{
public:
Point() { float x = 0, y = 0; }
void Input(int &count); //input values
Rectangle myRec;
private:
float x, y;
};
class Rectangle
{
public:
Rectangle(); //side1 - horizontal, side2 - vertical
void SetPoint(const Point point1, const Point point2, const Point point3, const Point point4) { LLPoint = point1; LRPoint = point2; URPoint = point3; ULPoint = point4; }
float CalcSides(Point LL, Point LR, Point UL, Point UR);
private:
Point LLPoint, LRPoint, ULPoint, URPoint;
float side1, side2, length, width, area, perimeter; //side1 - horizontal, side2 - vertical
};
float Rectangle::CalcSides(Point LL, Point LR, Point UL, Point UR)
{
side1 = (LR.x - LL.x);
}
如何访问我在 Rectangle 类中创建的点的 x 和 y 值?
【问题讨论】:
-
我忘了提到我在使用 Rectangle::CalcSides 函数时遇到了问题。它一直告诉我 x 值无法访问。
标签: c++ oop functional-programming inner-classes membership