I'm trying to create a C++ class that maintains a list of running instances of itself.
My .h file:
class FubberPWM {
/* code */
private:
uint8_t _duty;
uint8_t _instanceCount;
static FubberPWM _instances[];
}
My .cpp file, when trying to refrence the _instances array:
FubberPWM::loop() {
for(uint8_t i = 0; i < _instanceCount; i++) {
Serial.println(_instances[i]._duty); // Should output each instances _duty
}
}
I get the error "undefined reference to `FubberPWM::_instances'". Also, I don't know how to add "this" instance to the _instances array. I tried the following:
_instances[_instanceCount++] = this;
But that does not work. "invalid conversion from 'FubberPWM* const' to 'int'"
I'm new to C++, coming from the Java world. I know about pointers and references, but not very well.