P
poorboywilly
I've been unable to find any information on this through any search
engines. Is there any way to pass an unnamed (temporary) array to a
function?
e.g.
void f0(const int ar[5]);
void f1(const int ar[]);
f0( {1, 2, 3, 4, 5} ); //does not compile
f1( {1, 2, 3} ); //does not compile
int n_set[] = {1, 2, 3, 4, 5};
f0(n_set); //these both compile (of course)
f1(n_set);
I know I can use an STL container instead and pass an unnamed STL
container, but an STL container doesn't allow me to set construct it
with, say, 5 arbitrary values.
So I guess my question is, why can I not initialize a function
argument with the array "shorthand" notation, and is there an
alternative syntax that will allow this?
thanks,
--Jason
engines. Is there any way to pass an unnamed (temporary) array to a
function?
e.g.
void f0(const int ar[5]);
void f1(const int ar[]);
f0( {1, 2, 3, 4, 5} ); //does not compile
f1( {1, 2, 3} ); //does not compile
int n_set[] = {1, 2, 3, 4, 5};
f0(n_set); //these both compile (of course)
f1(n_set);
I know I can use an STL container instead and pass an unnamed STL
container, but an STL container doesn't allow me to set construct it
with, say, 5 arbitrary values.
So I guess my question is, why can I not initialize a function
argument with the array "shorthand" notation, and is there an
alternative syntax that will allow this?
thanks,
--Jason