This is the code snippet.
typedef struct Lib3dsMesh {
//..
float (*vertices)[3];
//..
}
void* lib3ds_util_realloc_array(void *ptr, in开发者_开发知识库t old_size, int new_size, int element_size) {
// Do something here.
return ptr;
}
mesh->vertices = lib3ds_util_realloc_array(mesh->vertices, mesh->nvertices, nvertices, 3 * sizeof(float));
When I compile this code in visual c++ it returns error "Cannot convert from void* to float(*)[3]".
I would like to know how to cast void * to float (*vertices)[3];
vertices
is a pointer to a 3-element array of float
. To do a cast from one pointer type to another, you generally use static_cast
:
void* result = lib3ds_util_realloc_array(
mesh->vertices, mesh->nvertices, nvertices, 3 * sizeof(float));
mesh-vertices = static_cast<float (*)[3]>(result);
精彩评论