Inline array declarations

This is my fist post on this forum, I want to know what the syntax is for inline array definitions (like arrays created when calling a function):

1
2
3
void foo(int*){};
/* ... */
foo(new int[] { 1, 2, 3 });


This code does not compile... I know theres a way of doing this but I can't seem to get the syntax (or find it anywhere).

If this same question apears in another thread, just post the link

Thanks,
- Alan

You have

int array[] = { 1, 2, 3, 4 };
foo( array );

or

boost::array<int,4> arr = { 1, 2, 3, 4 };
foo( array );

There is no way to "new" an array and initialize in the same line of code.
I originally wanted to know because I made a class:

 
class OPTION { ... };


which held a string*

then another class OPTIONLIST { ... }; that held OPTION*

Then I have a global array OPTIONLIST* oBASE = { ... };

since I need to declare about 30 instances OPTIONLIST everything it became very difficult to do it cleanly.

Thanks anyway...
Last edited on
Topic archived. No new replies allowed.