Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- //Class with no default constructor, as given in the asker's question.
- class MyClass
- {
- public:
- static const unsigned int dimension = 5;
- void (*myFunctions[dimension])();
- };
- //If the "test" object is declared globally, it will always have nullptr initialized values.
- //MyClass test;
- void setup()
- {
- Serial.begin(9600);
- while(!Serial);
- //If initialized like this, "test" WILL have uninitialized function pointers! Bad!
- MyClass test;
- //If initialized like this, "test" WILL NOT have uninitialized data!
- //MyClass test = {};
- // ==> It depends on whether the class has a constructor and how the object is declared
- // ==> always initialize to nullptr in constructor.
- for(auto x : test.myFunctions) {
- if(x == nullptr) {
- Serial.println("Good Null pointer.");
- } else {
- Serial.println("Functionpointer pointing to uninitialized data!");
- }
- }
- }
- void loop() { }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement