Default value for vector

hi, i have problems with default value for vector wich type is

1
2
3
4
5
6
7
struct s
{
int a;
int b;
}

void somefunction(int a, vector<s> & myVector = ??? );


what i must use instead of ???
thanks for help!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <vector>
#include <iostream>
using namespace std;

void printvector(const vector<int>& v = vector<int>())
{
    vector<int>::const_iterator it;
    cout << "vector content: ";
    for (it = v.begin(); it != v.end(); it++)
        cout << *it;
    cout << endl;
}

int main()
{
    vector<int> v;
    for (int i = 0; i < 10; i++)
        v.push_back(i);
    printvector();
    printvector(v);
}
vector content:
vector content: 0123456789


int c++0x there will be better options like:

 
    vector<int> v = {1,2,3,4,5};


and therefore

 
void somefunction(int a, const vector<int>& v = {1,2,3,4});


if you use the newest version of g++ or vs they support this maybe. But not sure, you can look it up in the net. Its still no standard, so not recommendable, but good to know.

Maikel
Last edited on
i do this another way, changed reference to pointer, and give pointer default value NULL, is it correct?
Topic archived. No new replies allowed.