0

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.

frodeborli
  • 1,537
  • 1
  • 21
  • 30
  • Also: http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix – chris Jun 15 '14 at 13:14
  • You need to specify static array size at compilation time. – kaman Jun 15 '14 at 13:15

0 Answers0