In C++11 you can. A note beforehand: Don't new the array, there's no need for that.
First, string[] strArray is a syntax error, that should either be string* strArray or string strArray[]. And I assume that it's just for the sake of the example that you don't pass any size parameter.
#include <string>
void foo(std::string* strArray, unsigned size){
// do stuff...
}
template<class T>
using alias = T;
int main(){
foo(alias<std::string[]>{"hi", "there"}, 2);
}
Note that it would be better if you didn't need to pass the array size as an extra parameter, and thankfully there is a way: Templates!
template<unsigned N>
void foo(int const (&arr)[N]){
// ...
}
Note that this will only match stack arrays, like int x[5] = .... Or temporary ones, created by the use of alias above.
int main(){
foo(alias<int[]>{1, 2, 3});
}
std::vectorinstead. When using c++11 you can construct them using initialization lists, e.g.void foo(vector<string>); foo({"hi", "there"});should work in c++11