Porting C code to C++, problem with casting void* from malloc to desired pointer
问题 I am currently porting some C code I wrote to C++ for fun. I am struggling with a malloc() call I make in C, with h and w being constants for simplicity reasons, but later exchanged with runtime constants: double (*g2)[h][w] = malloc(h * w * sizeof(double)); In C, this is an implicit conversion of a void* , and this of course doesn't fly with C++. I already tried casting this with reinterpret_cast<double[h][w]> , but this is still an invalid cast. I was wondering, how can I make this work in