你给出的上面的代码有这样的错误main.cpp: In constructor 'Rect::Rect(Point, Point)': main.cpp:20:32: error: no matching function for call to 'Point::Point()' Rect(Point tl_, Point br_) { ^ main.cpp:20:32: note: candidates are: main.cpp:11:5: note: Point::Point(int, int) Point(int x_, int y_) { ^ main.cpp:11:5: note: candidate expects 2 arguments, 0 provided main.cpp:8:7: note: constexpr Point::Point(const Point&) class Point { ^ main.cpp:8:7: note: candidate expects 1 argument, 0 provided main.cpp:8:7: note: constexpr Point::Point(Point&&) main.cpp:8:7: note: candidate expects 1 argument, 0 provided main.cpp:20:32: error: no matching function for call to 'Point::Point()' Rect(Point tl_, Point br_) { ^ main.cpp:20:32: note: candidates are: main.cpp:11:5: note: Point::Point(int, int) Point(int x_, int y_) { ^ main.cpp:11:5: note: candidate expects 2 arguments, 0 provided main.cpp:8:7: note: constexpr Point::Point(const Point&) class Point { ^ main.cpp:8:7: note: candidate expects 1 argument, 0 provided main.cpp:8:7: note: constexpr Point::Point(Point&&) main.cpp:8:7: note: candidate expects 1 argument, 0 provided 详细评判结果 »
时间: 2023-08-08 22:12:33 浏览: 55
这个错误是因为在 Rect 类的构造函数中调用了 Point 类的构造函数,但是没有提供任何参数。根据错误信息,Point 类有三个候选构造函数,但是都需要至少一个参数。
你需要在创建 Rect 对象时为 Point 对象提供所需的参数。例如:
```
Point tl(0, 0); // 创建左上角点
Point br(10, 10); // 创建右下角点
Rect rect(tl, br); // 创建矩形对象
```
这样就可以避免上述错误。
相关问题
Exception in thread "main" com.alibaba.fastjson.JSONException: default constructor not found
这个错误通常发生在使用FastJSON库时,当你尝试将一个Java对象序列化成JSON字符串时,FastJSON无法找到该对象的默认构造函数。
解决这个问题的方法是为你的Java对象添加一个默认构造函数,即无参数的构造函数。如果你已经有了一个有参构造函数,你可以手动添加一个无参构造函数,或者使用FastJSON的特殊注解为你的有参构造函数指定参数名称。
示例代码:
```java
public class MyClass {
private String name;
private int age;
// 有参构造函数
public MyClass(String name, int age) {
this.name = name;
this.age = age;
}
// 无参构造函数
public MyClass() {
}
// getters and setters
}
```
如果你已经有了一个无参构造函数但是还是遇到了这个问题,你可以检查一下你的类是否被正确地导入到你的项目中。
D:\Code\untitled1\mainwindow.cpp:14: error: expected type-specifier before 'knob' ..\untitled1\mainwindow.cpp: In constructor 'MainWindow::MainWindow(QWidget*)': ..\untitled1\mainwindow.cpp:14:22: error: expected type-specifier before 'knob' knob *knob = new knob(this); ^~~~
这个错误提示是因为编译器无法识别 'knob' 类型。可能的原因是您没有正确包含该类的头文件或未定义该类。
请确保您已经包含了 'knob' 类的头文件,并且该类已经定义和实现。另外,'knob' 类名应该是大写的,而不是小写的。
如果您已经包含了正确的头文件并且该类已经定义,您可能需要检查命名空间是否正确,或者您需要在类名前加上命名空间的限定符。
如果您无法解决这个问题,请提供更多的代码和错误信息,以便我能够更好地理解问题所在。