2
這是代碼片段。如何將void *轉換爲float(*)[3]在C++中?
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));
當我在visual C++中編譯此代碼時,它返回錯誤「無法從void *轉換爲float(*)[3]」。我想知道如何投射void * float(* vertices)[3];
演員像你投別的。目前,您不是在投射(顯式轉換),而是依賴於_implicit conversion_(如果不存在)。 –