I am trying to create a library, where I have an array of pointers to functions in it. This array is used by other functions in the library. This is the code of the header file:
class Lib {
public:
static void call();
static void (*caller[])();
private:
};
This is the code of the .cpp-file:
#include "Lib.h"
void (*caller[2])();
void Lib::call() {
caller[0]();
}
The sketch executing this is
#include <Lib.h>
void setup() {
Lib::call();
}
void loop() {}
When I try to compile this, I get the following error:
undefined reference to `Lib::caller'
collect2: error: ld returned 1 exit status
Mehrere Bibliotheken wurden für "Lib.h" gefunden
Another weird thing is that the error about the multiple found libraries goes away if I take away the line
Lib::call();
However, if I put the same code directly into the sketch like so:
void (*caller[2])();
void call() {
caller[0]();
}
void setup() {
call();
}
void loop() {}
I get no error. What's the problem here?