- default constructor
- copy constructor
- initializing constructor
The first one is pretty simple:
vector<int> x;
Nothing special.
The second one is also a famous type of constructor:
vector<int> x;With it, you can copy the contents of another vector. In the example above, you'll get a new vector y, whose contents is copied from vector x.
x.push_back(1);
x.push_back(2);
vector<int> y(x.begin(), x.end());
REP(i, y.size())
cout << y[i] << endl;
The last but not least is the initializing constructor. Literally you can initialize vectors at the same time as declaring them.
vector<int> x(10, 0);
You're creating a vector whose value is composed of 10 zeros.
0 件のコメント:
コメントを投稿