Of course you need to use reinterpret_cast. Look at the example https://perveevm.ru/docs/cpp/reference/en/cpp/memory/c/malloc.html