Bug? Multiple class instances - Static variables overwriting each other

Sorry to burst all of your misconceptions of static member variables in C++ but...
I got it to work just fine :wink: :wink: :wink: :wink:

Simply initialize the variable outside the class or at the top of the .cpp file.

Note to self: It is sometimes worth while to exclude "in arduino" from your searches on google instead use "in C++"

// Example of a properly used static variable used inside class, BUT INITIALIZED OUTSIDE OF CLASS! 
#define PrintArg(v){      \
  Serial.print(#v);       \
  Serial.print(" = ");    \
  Serial.println(v);      \
}

class Example{    
  public:
   int16_t ID;             // Member Variable
   static int16_t NextID;  
   
   Example(){              // Class contstructor
     ID = NextID++;       // reads static variable stores in id unique to each individual object
   }
   
   int16_t getNextID(){
      return(NextID);
   }
};

int16_t Example::NextID = 0;

Example Ex0, Ex1, Ex2;

void setup(){
   Serial.begin(115200);      // Start serial at 115200 baud rate
   while(!Serial);            // Wait for Serial Terminal to startup
   delay(300);                // Initial delay seems to work

   PrintArg(Ex0.ID);  // Prints:  "Ex0.ID = 0"  
   PrintArg(Ex1.ID);  //          "Ex1.ID = 1"
   PrintArg(Ex2.ID);  //          "Ex2.ID = 2"
   
   PrintArg(Ex0.getNextID());      // Prints: "3"
   PrintArg(Ex1.getNextID());      //         "3"
   PrintArg(Ex2.getNextID());      //         "3"
}
void loop(){ }