I’m trying to build a function that accepts an array in the following manner:
int inCommon = findCommon({54,56,2,10}, 4); int findCommon(int nums[], int len){ for(int i=0; i<len; i++) cout<<nums[i]<<endl; return 1; }
Note, that’s not actually what my function does, but I do loop through the array. I’m just trying to determine if it’s possible to pass an array like {54,56,2,10} instead of having to create an array and pass it? (like this:
int theArray[]= {54,56,2,10}; int inCommon = findCommon(theArray,4);
This is not possible at the time. However, in the next C++ standard C++0x, this will be done using initalizer lists:
See this presentation from Bjarne Stroustrup, and this article from Wikipedia
If you want to try C++0x features, you can check the last versions of gcc, that supports some of them.