I have simple function such as:
void fun(vector<int> vec)
{
//...
}
void fun(int* smth)
{
//...
}
No when i write in my program.
fun({2,3});
It calls me fun with vector argument i know it is in new C++ extended initializer lists but i would like to use new C++ and tell compiler that this is only a array of int’s how i can do it?
EDIT:
It would be nice to do it in 1 line 🙂
You can’t initialise a pointer with an array, because a pointer is not an array (despite the appearance in some situations that this is occuring, it is not).
You’ll have to pass a pointer to a pre-existing array. Alternatively, use the
vectoroverload — surely, you prefer this one anyway?! And if the two functions do different things then why are they overloads of one another (i.e. why does it matter)?