In an effort to minimise memory consumption in microcontroller code, I decided to create a struct to hold constant strings, then re-use these across the application so the strings only need to be stored once in memory.
I now want to use these for the keys in an icon map (as seen below), but I get the following error invalid use of non-static data member 'sensor_type::apparent_power'
.
What do I need to change to make this work? Is there a better structure to hold constant strings that I can statically access? I want to be able to access these globally without needing to create instances.
Could this be the solution or am I approaching the problem incorrectly?
struct sensor_type {
static constexpr const char *apparent_power = "apparent_power";
}
My original code:
struct sensor_type {
const char *apparent_power = "apparent_power";
}
// this works
if (tokens.at(1) == sensor_type::apparent_power) {
// ...
}
// this does not work
const std::map<const char*, const char*> sensor_icon_map {
{sensor_type::apparent_power, "\u0B17"}
}