5
explicit vector (size_type n, const T& value= T(), const Allocator& = Allocator());
vector<int> vec(10);
cout << "vec.size: " << vec.size() << endl;
for (vector<int>::const_iterator iter=vec.begin(); iter != vec.end(); ++iter)
{
cout << *iter << endl;
}
從VS2010輸出向量構造:C++標準:默認 「常量T&值」 在類型 'INT'
vec.size: 10
0
0
0
0
0
0
0
0
0
0
問題>: 基於最新C++標準,什麼是默認INT通過使用vectorObject(size_type)定義矢量對象時的值?
這裏你可以看到,VS2010輸出0作爲默認的int值。但我不知道這是C++標準所要求的。
有用的是,這也可以用於*數組類型的數組類型'T x [7]();'。 –
請參閱[這個答案](http://stackoverflow.com/questions/5950144/weird-c-code-snippet/5950176#5950176)的完整標準。 – ildjarn