How can I achieve a result like somebody would expect it according to the following code example:
// assuming: void myFunction( int* arr );
myFunction( [ 123, 456, 789 ] );
// as syntactical sugar for...
int values[] = { 123, 456, 789 };
myFunction( values );
The syntax I thought would work spit out a compile error.
- How can I define an argument array directly in the line where the function is called?
You can’t achieve that syntactic sugar with C++ code, not in C++03. The only place where braces are allowed, referring to elements of an array, is in initializing a named array:
Nowhere else. You can however achieve a similar effect with Boost.Assign: