0

I wonder how to convert a float array to a float* I have this situation :

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};it compiles alright.

Driss Bounouar
  • 3,182
  • 2
  • 32
  • 49

2 Answers2

6

This works OK:

float floatTab[3] = {12f, 0.5f, 3f}; float* ptr = floatTab;

FunkyCat
  • 448
  • 2
  • 6
  • Thanks. I was doing some extra changes to the same above code trying to give a reference instead of doing as simple as this. – Driss Bounouar Nov 17 '14 at 12:45
1

Prefer STL containers instead of C arrays (or others RAII-conform classes):

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.

vincentp
  • 1,433
  • 9
  • 12