我想制作多个结构,具有不同的设置......!它们都持有相同的变量(相同的名称等)!但是不同的实现!而且这个设置应该可以从另一个班级访问......这是最好的方法吗?还是我做错了什么?
啊:
class A
{
};
struct Color{
unsigned char r;
unsigned char g;
unsigned char b;
};
extern struct Settings settings;
A.cpp
struct settings{
Color firstcolor = {0,0,0}; //error: data member initializer is not allowed
Color secondcolor = {255,255,255}; //error: data member initializer is not allowed
};
struct anothersettings{
Color firstcolor = {255,255,255}; //error: data member initializer is not allowed
Color secondcolor = {0,0,0}; //error: data member initializer is not allowed
};
B.cpp
#include "A.h"
dosomethingwith(settings);