Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 结构及;函数-不命名类型_C++_Arduino_Esp8266 - Fatal编程技术网

C++ 结构及;函数-不命名类型

C++ 结构及;函数-不命名类型,c++,arduino,esp8266,C++,Arduino,Esp8266,我尝试使用函数和结构将十六进制颜色字符串转换为RGB值,然后返回数据 我已经设法完成了大部分工作,但我有点难以理解我的结构和函数应该如何协同工作 下面是我返回错误的代码RGB未命名类型 //Define my Struct struct RGB { byte r; byte g; byte b; }; //Create my function to return my Struct RGB getRGB(String hexValue) { char newVarOne[40

我尝试使用函数和结构将十六进制颜色字符串转换为RGB值,然后返回数据

我已经设法完成了大部分工作,但我有点难以理解我的结构和函数应该如何协同工作

下面是我返回错误的代码
RGB未命名类型

//Define my Struct
struct RGB {
  byte r;
  byte g;
  byte b;
};

//Create my function to return my Struct
 RGB getRGB(String hexValue) {
  char newVarOne[40];
  hexValue.toCharArray(newVarOne, sizeof(newVarOne)-1);
  long number = (long) strtol(newVarOne,NULL,16);
  int r = number >> 16;
  int g = number >> 8 & 0xFF;
  int b = number & 0xFF;

  RGB value = {r,g,b}
  return value;
}

//Function to call getRGB and return the RGB colour values
void solid(String varOne) {

  RGB theseColours;
  theseColours = getRGB(varOne);

  fill_solid(leds, NUM_LEDS, CRGB(theseColours.r,theseColours.g,theseColours.b));
  FastLED.show();
}
它出错的线路是:

RGB getRGB(String hexValue) {

有人能解释一下我做错了什么以及如何解决它吗?

如果你使用的是C编译器(与C++相反),你要么必须键入定义你的结构,要么在你使用类型的地方使用struct关键字

因此,要么:

typedef struct RGB {
  byte r;
  byte g;
  byte b;
} RGB;
然后:

RGB theseColours;
struct RGB theseColours;

然后:

RGB theseColours;
struct RGB theseColours;

但是,如果你使用C++编译器,那么如果你告诉我们错误发生在什么地方,它可能会帮助。

< P>如果你使用C编译器(而不是C++),你必须在你使用的类型中使用Type结构或使用Stutt关键字。 因此,要么:

typedef struct RGB {
  byte r;
  byte g;
  byte b;
} RGB;
然后:

RGB theseColours;
struct RGB theseColours;

然后:

RGB theseColours;
struct RGB theseColours;

但是,如果你使用C++编译器,那么如果你告诉我们错误发生在哪一行,它可能会帮助。< / P>哪条代码是编译器抱怨的?另外,语句

RGB value={r,g,b}
末尾缺少分号。编译器抱怨哪一行代码?另外,语句
RGB value={r,g,b}
结尾缺少分号。很抱歉,我用显示错误的行更新了我的问题。问题似乎有两个方面。RGB已被保留,我需要
typedef struct
抱歉,我已用显示错误的行更新了我的问题。问题似乎有两个方面。RGB已保留,我需要
typedef结构