相关疑难解决方法(0)

在其他类构造函数中使用类作为类型

我想在其他类 Rect 中使用类 Point。

\n
class Point\n{\n    int x, y;\n    public:\n    Point (int px, int py){\n        x = px;\n        y = py;\n    }\n};\n\nclass Rect\n{\n    Point top_left; \n    Point bottom_right;\n    public:\n    Rect (Point p1, Point p2){\n        top_left = p1;\n        bottom_right = p2;\n    }\n};\n
Run Code Online (Sandbox Code Playgroud)\n

错误消息是:“ main.cpp:31:30: 错误:没有调用 \xe2\x80\x98Rect::Point::Point()\xe2\x80\x99 的匹配函数”。根据我的理解, Rect 类的构造函数方法使用两个 Point 类型的参数来实例化 Rect 对象。我想我不能使用“Point”作为类型,因为它听起来像是编译器想要调用一个函数。错误消息对我没有帮助,所以我希望你能帮我。预先感谢您。

\n

c++ constructor class

0
推荐指数
1
解决办法
1261
查看次数

标签 统计

c++ ×1

class ×1

constructor ×1