简体   繁体   English

Arduino 1.6.3没有匹配功能可调用

[英]Arduino 1.6.3 no matching function for call to

Trying to create some inline helper classes for then drawing to display. 尝试创建一些内联帮助器类,然后将其显示出来。 Wrote some code this summer and then it compiled, now when running latest arduino it doesn't. 今年夏天写了一些代码,然后编译,现在运行最新的arduino却没有。

Error: 错误:

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.

Here's an example: 这是一个例子:

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:

}

... ...

Is there some changes for this in latest arduino. 最新的arduino是否对此有一些更改。 When trying to create a simple rectangle. 尝试创建简单的矩形时。

Error: 错误:

tmp.ino:20:1: error: 'rect' does not name a type
Error compiling.

Code: 码:

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() {
}

You have a Rectangle as part of your Image class, and aren't constructing it in your initialization list, so it defaults to getting default constructed, and you don't have a default constructor. 您将Rectangle作为Image类的一部分,并且没有在初始化列表中对其进行构造,因此它默认为默认构造,并且没有默认构造函数。

You need to initialize your Rectangle with the one passed in inside the initialization list: 您需要使用初始化列表中传入的矩形来初始化您的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;

}

Your second problem seems to be because you are trying to write code in the global namespace, outside of a function, which isn't valid. 第二个问题似乎是因为您试图在函数之外的全局名称空间中编写代码,这是无效的。 It compiled fine when I moved it to main() . 当我将其移至main()时,它编译良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM