diff --git a/include/coap/str.h b/include/coap/str.h index 72c1eaa1..2cd21543 100644 --- a/include/coap/str.h +++ b/include/coap/str.h @@ -96,8 +96,18 @@ void coap_delete_str_const(coap_str_const_t *string); * * @param string The const byte array to convert to a coap_str_const_t * */ -#define coap_make_str_const(string) \ +#ifdef __cplusplus +namespace libcoap { + struct CoAPStrConst : coap_str_const_t { + operator coap_str_const_t *() { return this; } + }; +} +#define coap_make_str_const(CStr) \ + libcoap::CoAPStrConst{sizeof(CStr)-1, reinterpret_cast(CStr)} +#else /* __cplusplus */ +#define coap_make_str_const(string) \ (&(coap_str_const_t){sizeof(string)-1,(const uint8_t *)(string)}) +#endif /* __cplusplus */ /** * Compares the two strings for equality