[英]How to cast void * to float (*)[3] in c++?
This is the code snippet. 这是代码段。
typedef struct Lib3dsMesh {
//..
float (*vertices)[3];
//..
}
void* lib3ds_util_realloc_array(void *ptr, int 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]". 当我在visual c ++中编译此代码时,它返回错误“无法从void *转换为float(*)[3]”。
I would like to know how to cast void * to float (*vertices)[3]; 我想知道如何将void *转换为float(*顶点)[3];
vertices
is a pointer to a 3-element array of float
. vertices
是指向float
的3元素数组的指针 。 To do a cast from one pointer type to another, you generally use static_cast
: 要从一种指针类型转换为另一种指针类型,通常使用
static_cast
:
void* result = lib3ds_util_realloc_array(
mesh->vertices, mesh->nvertices, nvertices, 3 * sizeof(float));
mesh-vertices = static_cast<float (*)[3]>(result);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.