[英]C++ convert a float array to float* (pointer)
I wonder how to convert a float array to a float* I have this situation : 我想知道如何将float数组转换为float *我有这种情况:
float* floatTab = {12f, 0.5f, 3f};
It gives me an error here. 这给我一个错误。 but if I write it like this
float floatTab[3] = {12f, 0.5f, 3f};
但是如果我这样写它,
float floatTab[3] = {12f, 0.5f, 3f};
it compiles alright. 它可以编译。
这样可以正常工作:
float floatTab[3] = {12f, 0.5f, 3f}; float* ptr = floatTab;
Prefer STL containers instead of C arrays (or others RAII-conform classes): 首选STL容器而不是C数组(或其他符合RAII的类):
const std::array<float, 3> array = { 1.f, 2.f, 3.f };
float *ptr = &array[0];
Don't forget to include <array>
and <initializer_list>
to compile this code. 不要忘记包含
<array>
和<initializer_list>
来编译此代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.