Advertisement
Guest User

Untitled

a guest
Feb 15th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <Arduino.h>
  2.  
  3. //Class with no default constructor, as given in the asker's question.
  4. class MyClass
  5. {
  6. public:
  7. static const unsigned int dimension = 5;
  8. void (*myFunctions[dimension])();
  9. };
  10.  
  11. //If the "test" object is declared globally, it will always have nullptr initialized values.
  12. //MyClass test;
  13.  
  14. void setup()
  15. {
  16.     Serial.begin(9600);
  17.     while(!Serial);
  18.  
  19.     //If initialized like this, "test" WILL have uninitialized function pointers! Bad!
  20.     MyClass test;
  21.     //If initialized like this, "test" WILL NOT have uninitialized data!
  22.     //MyClass test = {};
  23.     // ==> It depends on whether the class has a constructor and how the object is declared
  24.     // ==> always initialize to nullptr in constructor.
  25.  
  26.  
  27.     for(auto x : test.myFunctions) {
  28.         if(x == nullptr) {
  29.             Serial.println("Good Null pointer.");
  30.         } else {
  31.             Serial.println("Functionpointer pointing to uninitialized data!");
  32.         }
  33.     }
  34. }
  35.  
  36. void loop() { }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement