I have a class that changes the color of something based on button inputs. I'd like to predefine a bunch of "colors" so that a state machine can simply copy the constant structs defined in header to some variable to change colors.
I don't understand why the compiler is hunky-dory with the below code but the Linker can't deal with it. Is there a better pattern for defining constant structs? Should I just make them non-static non-const and live with it?
class ColorManager {
public:
ColorManager () {
}
// ProcessButton uses the static constexpr structs defined below
void ProcessButton(uint8_t button_state);
private:
// Color_t is defined elsewhere as a struct of R, G, B fields
static constexpr Color_t kColorWhite = {100, 100, 100};
static constexpr Color_t kColorRed = {100, 0, 0};
static constexpr Color_t kColorPurple = {100, 0, 70};
};
Edit: Here's an example error message:
src/color_manager.o: In function `ColorManager::ProcessButton(uint8_t button_state)':
color_manager.cc:(.text+0x224): undefined reference to `ColorManager::kColorWhite'
collect2: error: ld returned 1 exit status
-std=c++11standpoint)