Đó là lỗi trong cả VS2012 và VS2013 vì nó không tuân thủ tiêu chuẩn C++ 11 (với _HAS_CPP0X
được định nghĩa là 1):
C++ 03 23.1.1 [lib.sequence.reqmts]/9 nói:
For every sequence defined in this clause and in clause 21:
— the constructor template <class InputIterator> X(InputIterator f, InputIterator l, const Allocator& a = Allocator())
shall have the same effect as:
X(static_cast<typename X::size_type>(f), static_cast<typename X::value_type>(l), a)
if InputIterator
is an integral type.
nhưng từ 11 23.2.3 C++ [sequence.reqmts]/14:
For every sequence container defined in this Clause and in Clause 21:
— If the constructor template <class InputIterator> X(InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type())
is called with a type InputIterator
that does not qualify as an input iterator, then the constructor shall not participate in overload resolution.
Đó constructor không nên được xem xét ở tất cả
More đây: https://stackoverflow.com/a/12432482/1938163
Để giải quyết sự cố, bạn có thể "giúp giải quyết quá tải một chút", ví dụ:
std::vector<int> v(static_cast<std::vector<int>::size_type>(N), M);
Nguồn
2014-09-18 17:21:11
Cả gcc và tiếng kêu đều ổn với điều này, có vẻ như là lỗi. –
Tôi mạnh mẽ nghi ngờ lỗi của VS .. –