This is so wierd, i am coding a pixel manipulation library in C++. So i want to have a class filled with color presets. Color is a class with a struct that looks like:
Color(int r, int g, int b, int a) And if i declare it outside of any classes as:
static const Color COL_BLACK = Color(0, 0, 0, 255); That shows no error in Visual Studio Code. But however when i structure like this:
class Colors { public: static const Color Black = Color(0, 0, 0, 255); }; The equal sign has a red squiggly line under it, but when i hover my mouse over it doesn't tell me what is wrong. What is wrong?
Note that i want it to be called like so:
Color newCol = Colors::Black;
static inline const Color Black = Color(0, 0, 0, 255);for the static member inColors. ;-)staticmembers in aclassdeclaration are a potential violation of the One Definition Rule (ODR) because the class declaration (in a header) could be repeated. In older standards, it was necessary to move the definition of static members into one translation unit (a.cppfile). Since recent standards (I believe C++17), an alternative option is thestatic inline(with the requirement that thestatic inlined hast to be equal at every time when its seen by the compiler again).