This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Enum forward declaration in c++

Hi there

I'm struggling with the usbd_cdc_acm example.

I want combine the ble_app_uart and the usbd_cdc_acm example to use my ble central role with nus and usb at the pca10059.

For my project I have to add a communication stack, which is coded in c++11.

it works with the ble_app_uart peripheral example, but not with the usbd.

There are two files which are struggeling against c++.

app_usbd_cdc_acm.h and app_usbd_cdc_acm_internal.h

and this is the problem:

//app_usbd_cdc_acm.h

typedef enum app_usbd_cdc_acm_user_event_e {
    APP_USBD_CDC_ACM_USER_EVT_RX_DONE,     /**< User event RX_DONE.    */
    APP_USBD_CDC_ACM_USER_EVT_TX_DONE,     /**< User event TX_DONE.    */

    APP_USBD_CDC_ACM_USER_EVT_PORT_OPEN,   /**< User event PORT_OPEN.  */
    APP_USBD_CDC_ACM_USER_EVT_PORT_CLOSE,  /**< User event PORT_CLOSE. */
} app_usbd_cdc_acm_user_event_t;

// app_usbd_cdc_acm_internal.h

/*lint -save -e165*/
/**
 * @brief Forward declaration of @ref app_usbd_cdc_acm_user_event_e.
 *
 */
enum app_usbd_cdc_acm_user_event_e;

/*lint -restore*/

/**
 * @brief User event handler.
 *
 * @param[in] p_inst    Class instance.
 * @param[in] event     User event.
 *
 */
typedef void (*app_usbd_cdc_acm_user_ev_handler_t)(app_usbd_class_inst_t const *    p_inst,
                                                 enum app_usbd_cdc_acm_user_event_e event);

the errors are:

Compiling file: main.cpp
In file included from .//components/libraries/usbd/class/cdc/acm/app_usbd_cdc_acm.h:58,
                 from .//main.cpp:57:
.//components/libraries/usbd/class/cdc/acm/app_usbd_cdc_acm_internal.h:64:6: error: use of enum 'app_usbd_cdc_acm_user_event_e' without previous declaration
 enum app_usbd_cdc_acm_user_event_e;
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.//components/libraries/usbd/class/cdc/acm/app_usbd_cdc_acm_internal.h:76:55: error: use of enum 'app_usbd_cdc_acm_user_event_e' without previous declaration
                                                  enum app_usbd_cdc_acm_user_event_e event);
                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from .//main.cpp:59:

I tryed to do the enum class app_usbd_cdc_acm_user_event_e: int {...} conversion but it doesn't work. Just caused some weird errors. I tryed some other things but nothing helped.

I'm using sdk15.3 with s140. Compiling with gnu-arm (arm.none-eabi -g++ and -gcc) version <gcc-arm-none-eabi-8-2018-q4-major> and working with eclipse.

Everything works when I change main.cpp to .c and compile in C.

Maybe someone has a solution for this.

Greetings N3210

Related