there are definitely things to fix, but kudos for taking the time to share your notes.
I have experimentally confirmed that I get compiler errors if each class name does
not start with a capital.
here is an example of class names starting with non capital letters and all is working fine
class box {
public:
uint8_t val;
box(uint8_t v) : val(v) {} // constructor
uint8_t value() {return val;}
};
class cat {
public:
uint8_t val;
cat(uint8_t v) : val(v) {} // constructor
uint8_t value() {return val;}
};
class dog {
public:
uint8_t val;
dog(uint8_t v) : val(v) {} // constructor
uint8_t value() {return val;}
};
box aBox(10);
cat aCat(20);
dog aDog(30);
void setup() {
Serial.begin(115200);
Serial.print(F("aBox -> ")); Serial.println(aBox.value());
Serial.print(F("aCat -> ")); Serial.println(aCat.value());
Serial.print(F("aDog -> ")); Serial.println(aDog.value());
}
void loop() {}
it's just a convention to name the class starting with a capital letter. The language is case sensitive, so Box and box are two different things.
I was unable to find a way to have a constructor with no arguments that would compile without errors using the Arduino IDE.
here is an example of such a constructor with no argument
class Box
{
public:
uint8_t val;
Box() {val = 0;} // constructor
void setVal(uint8_t v) {val = v;}
uint8_t getVal() {return val;}
};
Box aBox;
void setup() {
Serial.begin(115200);
aBox.setVal(33);
Serial.print(F("aBox -> ")); Serial.println(aBox.getVal());
}
void loop() {}
I empirically found that the constructor must not be inside of any function. For example, if I call the constructor within setup(), the compiler will complain that it doesn’t recognizer any of the members of its class.
here is an example of dynamic instantiation, within the setup with a global pointer
class Box
{
public:
uint8_t val;
Box() {val = 0;} // constructor
void setVal(uint8_t v) {val = v;}
uint8_t getVal() {return val;}
};
Box* aBox;
void setup() {
Serial.begin(115200);
aBox = new Box;
aBox->setVal(33);
Serial.print(F("aBox -> ")); Serial.println(aBox->getVal());
}
void loop() {}
or here is an example of just dynamic instantiation of a class instance that is local to the setup() function
class Box
{
public:
uint8_t val;
Box() {val = 0;} // constructor
void setVal(uint8_t v) {val = v;}
uint8_t getVal() {return val;}
};
void setup() {
Box aBox;
Serial.begin(115200);
aBox.setVal(33);
Serial.print(F("aBox -> ")); Serial.println(aBox.getVal());
}
void loop() {}
all your empirically found knowledge is based on misconceptions or failure to get things done the right way. You should read a proper C++ tutorial.
In general, I treat compiler errors related to a library as telling me I did something
wrong. I do not try to make sense of its details
Yes, compiler errors means there is something wrong. But making sense of the details can definitely help you understand what got wrong in the first place. (I reckon sometimes the compiler is cryptic)
Again, kudos and +1 karma for taking the time to jot that down, and expose your work here to the community - not always the most tender one for weird claims
... bare with us, constructive feedback and criticism is something positive.