Can anyone explain why the test code listed below compiles with the error?
mctest.cpp:3:35: error: 'mqttCallback_t' has not been declared
void addSubscription(char* topic, mqttCallback_t cback);
^
Note that 3:35 points to the typedef … not the line actually printed with the error.
I’m using a vector to store MQTT topics and a callback function pointer for each topic. The call back functions will not be members of the class.
#include "Particle.h"
#include <vector>
typedef void (*mqttCallback_t)(char*, byte*, unsigned int);
class MqttClient{
struct MqttSubscription {
char topic[64];
mqttCallback_t callback;
};
private:
byte brokerIP[4];
uint16_t maxPacketLength;
bool sessionActive;
std::vector<MqttSubscription> subList;
public:
void addSubscription(char* topic, mqttCallback_t cback) {
MqttSubscription sub;
strncpy(sub.topic, topic, sizeof(sub.topic));
sub.callback = cback;
this->subList.push_back(sub);
}
};
void setup() {
}
void loop() {
}