尝试创建一些内联辅助类,然后绘制以显示。 今年夏天编写了一些代码然后编译,现在运行最新的arduino时它没有。
错误:
tmp.ino: In constructor 'Image::Image(Rectangle, String, String, String, String, String, String, String, String, String, String)':
tmp.ino:24:187: error: no matching function for call to 'Rectangle::Rectangle()'
tmp.ino:24:187: note: candidates are:
tmp.ino:11:5: note: Rectangle::Rectangle(int, int, int, int)
tmp.ino:11:5: note: candidate expects 4 arguments, 0 provided
tmp.ino:3:7: note: Rectangle::Rectangle(const Rectangle&)
tmp.ino:3:7: note: candidate expects 1 argument, 0 provided
Error compiling.
以下是一个例子:
class Rectangle {
private:
public:
int x;
int y;
int width;
int height;
Rectangle(int ix, int iy, int iwidth, int iheight) {
x = ix;
y = iy;
width = iwidth;
height = iheight;
}
};
class Image {
private:
public:
Rectangle bounds;
String images[10];
Image(Rectangle s_bounds, String s1, String s2 = "", String s3 = "", String s4 = "", String s5 = "", String s6 = "", String s7 = "", String s8 = "", String s9 = "", String s10 = "") {
bounds = s_bounds;
images[0] = s1;
images[1] = s2;
images[2] = s3;
images[3] = s4;
images[4] = s5;
images[5] = s6;
images[6] = s7;
images[7] = s8;
images[8] = s9;
images[9] = s10;
}
void UpdatePosition( int s_x, int s_y ) {
bounds.x = s_x;
bounds.y = s_y;
}
};
void setup() {
// put your setup code here, to run once:
Rectangle rect = Rectangle(0,0,200,29);
rect.x = 20;
Image img = Image(Rectangle(0,0,10,10), "img.RAW");
}
void loop() {
// put your main code here, to run repeatedly:
}
...
最新的arduino是否有一些变化。在尝试创建一个简单的矩形时。
错误:
tmp.ino:20:1: error: 'rect' does not name a type
Error compiling.
代码:
class Rectangle {
private:
public:
int x;
int y;
int width;
int height;
Rectangle(int ix, int iy, int iwidth, int iheight) {
x = ix;
y = iy;
width = iwidth;
height = iheight;
}
};
Rectangle rect = Rectangle(0,0,200,29);
rect.x = 20;
void setup() {
}
void loop() {
}
答案 0 :(得分:0)
您的Rectangle
类中有一个Image
,并且没有在初始化列表中构建它,因此它默认为默认构造,并且您没有默认构造函数
您需要使用初始化列表中传入的Rectangle初始化Rectangle:
Image(Rectangle s_bounds, String s1, String s2 = "", String s3 = "", String s4 = "", String s5 = "", String s6 = "", String s7 = "", String s8 = "", String s9 = "", String s10 = "")
: bounds(s_bounds)
{
images[0] = s1;
images[1] = s2;
images[2] = s3;
images[3] = s4;
images[4] = s5;
images[5] = s6;
images[6] = s7;
images[7] = s8;
images[8] = s9;
images[9] = s10;
}
你的第二个问题似乎是因为你试图在函数之外的全局命名空间中编写代码,这是无效的。当我把它移到main()
时,它编译得很好。