gfvalvo:
One thing that comes to mind is I don't think you can 'malloc(sizeof(settings_type))' when the struct / class contains a method. You have to 'new' it.
I think you can.
struct Settings {
int one;
int two;
float three;
Settings () : one(10), two(20), three(30.0) {}
bool operator==(Settings const & other) const {
return one == other.one &&
two == other.two &&
abs(three - other.three) < 0.0001;
}
bool operator!=(Settings const & other) const {
return !(*this == other);
}
};
const Settings defaultSet;
Settings dynamicSet;
void setup() {
Serial.begin(250000);
void* checker = malloc(sizeof(Settings));
Settings* randomSet = reinterpret_cast<Settings*>(checker);
if (*randomSet == defaultSet) {
Serial.println(F("randomSet happens to be same as default"));
} else {
Serial.println(F("randomSet is different from default"));
}
free(checker);
if (dynamicSet == defaultSet) {
Serial.println(F("both start up the same"));
}
dynamicSet.one += 1;
if (dynamicSet != defaultSet) {
Serial.println(F("dynamicSet was changed"));
}
}
void loop() {}
randomSet is different from default
both start up the same
dynamicSet was changed
Added: Using class with public: gives exactly the same result and behaviour.
Why would you want to leave out any initialization in the first place?