# Compile error with function pointer in a class vector

**URL:** <https://community.particle.io/t/compile-error-with-function-pointer-in-a-class-vector/49391>\
**Category:** Troubleshooting\
**Created:** [April 28, 2019, 2:51pm UTC](https://community.particle.io/t/compile-error-with-function-pointer-in-a-class-vector/49391 "2019-04-28T14:51:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bear](https://avatars.discourse-cdn.com/v4/letter/b/ac8455/32.png) [@Bear](https://community.particle.io/u/Bear)\
**Post date:** [April 28, 2019, 2:51pm UTC](https://community.particle.io/t/compile-error-with-function-pointer-in-a-class-vector/49391/1 "2019-04-28T14:51:17Z")

</div>

Can anyone explain why the test code listed below compiles with the error?

```auto
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.

```cpp
#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() {

}

```

---

<div class="post-metadata">

**Author:** ![justicefreed\_amper](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/justicefreed_amper/32/16477_2.png) [@justicefreed\_amper](https://community.particle.io/u/justicefreed_amper)\
**Post date:** [May 1, 2019, 4:56pm UTC](https://community.particle.io/t/compile-error-with-function-pointer-in-a-class-vector/49391/2 "2019-05-01T16:56:33Z")

</div>

I believe it isn’t working because of the way the preprocessor works in the compilation process. An attempt is made to declare the class forward in some fashion and then that moves it before the typedef, which is not moved. If you move your typedef into a header included by this file it compiles for me.

---

<div class="post-metadata">

**Author:** ![Bear](https://avatars.discourse-cdn.com/v4/letter/b/ac8455/32.png) [@Bear](https://community.particle.io/u/Bear)\
**Post date:** [May 2, 2019, 2:27pm UTC](https://community.particle.io/t/compile-error-with-function-pointer-in-a-class-vector/49391/3 "2019-05-02T14:27:39Z")

</div>

Thank you … Moving the typedef to a .h file solved my problem, and it’s nice to have a sense for why that made a difference. I greatly appreciate your help !!!
