程序:
#include<vector>
int main() {
std::vector<int>::size_type size=3;
std::vector<int> v{size};
}
编译时
g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
产生错误:
ppp.cpp: In function ‘int main()’:
ppp.cpp:5:28: error: narrowing conversion of ‘size’ from ‘std::vector<int>::size_type {aka long unsigned int}’ to ‘int’ inside { } [-fpermissive]
ppp.cpp:5:28: error: narrowing conversion of ‘size’ from ‘std::vector<int>::size_type {aka long unsigned int}’ to ‘int’ inside { } [-fpermissive]
在http://www.cplusplus.com/reference/stl/vector/vector/上写着
explicit vector ( size_type n, const T& value= T(), const Allocator& = Allocator() );
我希望使用该构造函数。
有人可以解释一下吗?