   How to store an array created with  in C++
  I tried this:float* foo = {3.0f, 3.0f, 3.0f, 1.0f};But I get syntax errors. How do I store an array created like this?   
  That's not an array, that's a pointer. You're probably looking for this:float Array[3] = { 1.0f, 2.0f, 3.0f };It's a confusing one for beginners, since you can use the array operator [] to index from a pointer too:float Array[3] = { 1.0f, 2.0f, 3.0f };float* ArrayPtr = Array;float LastValue = ArrayPtr[2];;Quote:Original post by deadstarThat's not an array, that's a pointer. You're probably looking for this:*** Source Snippet Removed ***It's a confusing one for beginners, since you can use the array operator [] to index from a pointer too:*** Source Snippet Removed ***I need to store it without knowing it's size though...   ;Quote:Original post by SteveDeFactoI need to store it without knowing it's size though...float foo[] = {3.0f, 3.0f, 3.0f, 1.0f};;  You know the size because you're adding all the values between the brackets...If you want a variable sized array you probably want to use std::vector.-me   ;Quote:Original post by Adam_42Quote:Original post by SteveDeFactoI need to store it without knowing it's size though...float foo[] = {3.0f, 3.0f, 3.0f, 1.0f};also I need to send it to a function but this does not seem to work.example:void foo( float data[] ){}...foo( {3.0f, 3.0f, 3.0f, 1.0f} );...;Quote:Original post by SteveDeFactoalso I need to send it to a function but this does not seem to work.Congratulations you just hit a C++ syntax limitation. You can't have a temporary array that I'm aware of. The exception being c-string literals.Why do you want to do this? There's probably another way to get the result you want.;Quote:Original post by nobodynewsQuote:Original post by SteveDeFactoalso I need to send it to a function but this does not seem to work.Congratulations you just hit a C++ syntax limitation. You can't have a temporary array that I'm aware of. The exception being c-string literals.Why do you want to do this? There's probably another way to get the result you want.I can do it with luabind:void set_variable(std::string variable, UINT count, luabind::object const& data )EDIT: wait that was just in lua though...   ;  OK what I need to do is pass a series of floats to the function. I can create the array the traditional way but this would require more code then I want I.E:std::vector<float> data;data.push_back(1.0f);data.push_back(7.0f);data.push_back(2.3f);set_variable("Diffuse", 3, &data[0] );Is there anyway to get this into one line?   ;  The reason it doesn't work is because you need to allocate memory first (on the heap, not the stack like a normal array) before using a pointer as an array.  If you absolutely need a pointer, then do this instead:straight C version:// Let's say you want to allocate memory for 3 floats in this// pointer, call malloc and multiply the size of the variable// with the number of variables you would want in a normal// array, like so.float* foo = (float*) malloc( sizeof( float ) * 3 );// Now you can use it like a normal arrayfoo[0] = 1.0f;foo[1] = 2.0f;foo[2] = 3.0f;// Don't forget to free the memory you allocated before you exit// or else you will cause a memory leak.free( foo );EDIT: Didn't see your last post.  I am curious of your intentions...Hopefully this helps you learn a new trick or two =DEDIT: I didn't see your last post until now.  I am curious of your intentions.   