I know this question was asked almost 10 years ago. But for anyone finding its solution now, I've got exactly that for you. I basically have three different methods:
void test(vector<int>vec = vector<int>(10, 0){//definition}
This can be used if it has to be if the default vector has a given size with a common initialiser value.
void test(vector<int>vec = vector<int>{1, 2, 3, 4}){//definition}
This can be used if it has to be if the default vector has a given size with a different initialiser values.
A different approach could be to define a global vector object as:
vector<int> globalvector;
(initialised or uninitialised) and the passing this object as default value as
void test(vector<int>vec = globalvector){//definition}
An important benefit of the last one is that it gives more control over the default value itself as functions can be used to assign values to this globalvector
before control reaches the test()
function. Another benefit is that (as far I've yet found), if the function involves passing by reference, this works just as fine as:
void test(vector<int>& vec = globalvector){//definition}
unlike the former two.