结构和函数 - 不命名类型
Struct & Function - Does not name a type
我正在尝试使用函数和结构将十六进制颜色字符串转换为 RGB 值,然后返回数据
我已经设法完成了大部分工作,但我有点难以理解我的结构和函数应该如何协同工作。
这是我的代码,返回错误RGB does not name a type
//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++),则必须对结构进行 typedef 或无论在哪里使用该类型,都必须使用 struct 关键字。
所以要么是:
typedef struct RGB {
byte r;
byte g;
byte b;
} RGB;
然后:
RGB theseColours;
或
struct RGB {
byte r;
byte g;
byte b;
};
然后:
struct RGB theseColours;
但是,如果您使用的是C++编译器,那么如果您告诉我们错误发生在哪一行可能会有所帮助。
相关文章:
- 特征::矩阵<双精度,1,3> 结构类型函数中的返回类型函数
- 将C++子类成员函数(虚拟实现)传递给 C 类型函数指针
- C++ 这里有一个返回 (24) 的布尔返回类型函数
- 使用SFINAE来检测void返回类型函数的存在
- 使用此类型函数有什么优势
- 为什么此函数通过类型函数指针调用后,呼叫明智地行为
- 如何使用无类型函数指针调用C++成员函数
- 模板返回类型函数如何在C++中工作
- 具有通用类型函数的动态库[C ]
- 如何在返回类型函数模板的专用化中使用派生类型?( "couldn't infer template argument" )
- Bon appetit :从 int 返回类型函数在 main() 中打印字符串
- 对于需要其他模板参数的类型函数的部分模板专业化
- c++错误的参数类型-函数指针
- 延迟评估模板类型函数
- 在引用或指针返回类型函数上输入
- 具有指针数据类型的非类型函数模板参数
- STL中使用的C++自定义比较类型(函数谓词与较少结构)
- C++模板基类的非类型函数模板的 using 声明
- 字符串到类型函数,模板专用化使调用统一
- 自由类型函数可以接受 Unicode 文件名吗?