How can i make sure that the somecolor that i implement keeps his value when you use it in another class?
struct.h
struct Color{
unsigned char r;
unsigned char g;
unsigned char b;
};
Color someColor;
//if i define the color here it says...:
Color someColor = {255,255,255}; //error: data member inializer not allowed
struct.cpp
struct::Color someColor = {255,255,255};
someotherclass.cpp
struct *str = new struct();
str->someColor.r //is not the correct value /not set
You need to declare it in the header:
extern Color someColor;
and define it in the .cpp file:
Color someColor = {255, 255, 255};
Side note, your syntax struct::Color
is highly misleading. It's parsed as struct ::Color
, and in C++ terms, it's equivalent to ::Color
or just Color
(unless you're inside a namespace).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With