在一个类中创建结构并在另一个类中实现并在另一个类中使用的最佳方法是什么?
结构体.h
struct White{
unsigned char r;
unsigned char g;
unsigned char b;
Color() : r(255), g(255), b(255){}
};
struct Black{
unsigned char r;
unsigned char g;
unsigned char b;
Color() : r(0), g(0), b(0){}
};
White white; //works fine
Black black = {255, 255, 255}; //*error: data member initializer is not allowed!* (because of unsigned char maybe?)
**OR**
Black black; black.r = 255; //*error: this declaration has no storage class or type specifier!*
另一个类.cpp
#include "Structs.h"
Structs *str = new Structs();
str->white.r //works, is 255
str->black.r //should be 255 too