I am migrating my project to C++. Everything in the SDK works so far except NRF_BLE_GATT_DEF(). This returns the error C++ requires a type specifier for all declarations. Is there a workaround?
I am migrating my project to C++. Everything in the SDK works so far except NRF_BLE_GATT_DEF(). This returns the error C++ requires a type specifier for all declarations. Is there a workaround?
Another error occurs in the APP_USBD_CDC_ACM_GLOBAL_DEF:
static void cdc_acm_user_ev_handler(app_usbd_class_inst_t const * p_inst, app_usbd_cdc_acm_user_event_t event); /** * @brief CDC_ACM class instance * */ APP_USBD_CDC_ACM_GLOBAL_DEF(m_app_cdc_acm, cdc_acm_user_ev_handler, CDC_ACM_COMM_INTERFACE, CDC_ACM_DATA_INTERFACE, CDC_ACM_COMM_EPIN, CDC_ACM_DATA_EPIN, CDC_ACM_DATA_EPOUT, APP_USBD_CDC_COMM_PROTOCOL_AT_V250);
Error invalid conversion from 'void (*)(const app_usbd_class_inst_t*, app_usbd_cdc_acm_user_event_t)' {aka 'void (*)(const app_usbd_class_inst_s*, app_usbd_cdc_acm_user_event_e)'} to 'app_usbd_cdc_acm_user_ev_handler_t' {aka 'void (*)(const app_usbd_class_inst_s*, int)'}
Changing the event type to int gives another error about initialization.
Actually, when I convert it to int:
static void cdc_acm_user_ev_handler(app_usbd_class_inst_t const * p_inst, int event);
Error designator order for field 'app_usbd_cdc_acm_inst_t::comm_interface' does not match declaration order in 'app_usbd_cdc_acm_inst_t'
Hi,
Which example are you trying to convert to C++.? Also, which compiler are you using.?
Regards,
Swathy
Data structure assignments must be in the order as the defined in the structure in C++. You need to re-order the assignments. For example.
typedef struct {
int a;
float b;
char c;
} X_t;
// Wrong order, rejected by C++, accepted by C
X_t failedAssign = {
.b = 1.0,
.a = 3,
};
// Correct order, accepted by both
X_t goodAssign = {
.a = 3;
.b = 1.0,
};
Unfortunately there are a lot of those in the SDK.
SDK 16.0 using usb_cdc_acm example. GCC with -std=C++11.
My workaround so far has been to place the above definition and callback function in a C module and to pass the arguments to the real callback in the C++ module.
Also, when including app_usbd_cdc_acm.h in the C++ module it complained about a forward enum declaration. I had to move the enum declaration into the app_usbd_cdc_acm_internal.h file and protect it with a #define:
#ifndef _APP_USBD_CDC_
#define _APP_USBD_CDC_
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;
#endif // !_APP_USBD_CDC_
/*lint -save -e165*/
/**
* @brief Forward declaration of @ref app_usbd_cdc_acm_user_event_e.
*
*/
enum app_usbd_cdc_acm_user_event_e;