我想在其他类 Rect 中使用类 Point。
\nclass 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};\nRun Code Online (Sandbox Code Playgroud)\n错误消息是:“ main.cpp:31:30: 错误:没有调用 \xe2\x80\x98Rect::Point::Point()\xe2\x80\x99 的匹配函数”。根据我的理解, Rect 类的构造函数方法使用两个 Point 类型的参数来实例化 Rect 对象。我想我不能使用“Point”作为类型,因为它听起来像是编译器想要调用一个函数。错误消息对我没有帮助,所以我希望你能帮我。预先感谢您。
\n