Mar 26, 2010 at 11:09am Mar 26, 2010 at 11:09am UTC
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 Mar 26, 2010 at 11:11am Mar 26, 2010 at 11:11am UTC
Mar 26, 2010 at 12:01pm Mar 26, 2010 at 12:01pm UTC
i do this another way, changed reference to pointer, and give pointer default value NULL, is it correct?