2014-09-18 7 views

Odpowiedz

12

To błąd zarówno w VS2012, jak i VS2013, ponieważ nie jest zgodny ze standardem C++ 11 (z _HAS_CPP0X zdefiniowanym jako 1)

C++ 03 23.1.1 [lib.sequence.reqmts]/9 mówi:

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.

lecz z C++ 11 23.2.3 [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.

że konstruktor nie powinny były zostać uznane za wszelką

więcej tutaj: https://stackoverflow.com/a/12432482/1938163

Aby obejść ten problem, można "pomóc w rozwiązaniu nadmiernego przeciążenia nieco", np.

std::vector<int> v(static_cast<std::vector<int>::size_type>(N), M); 
10

Ponieważ C++ 11 konstruktor vector przyjmujący dwa InputIterators powinien być wyłączony, jeśli dwa argumenty nie są iteratorami. VS2013 nie implementuje tego poprawnie.

2

To jest Visual Studio 2013 bug, od błędu jest generowany (see it live), to tylko niewielka część:

[...]

see reference to function template instantiation 'std::vector>::vector<,void>(_Iter,_Iter)' being compiled

[...]>

on próbuje użyć konstruktora, że ​​trwa dwa wejściowe iteratory. Który byłby błąd, zarówno gcc i clang są w porządku z tym kodem.

Możemy że w C++ 11 that constructor nie powinny być uznane:

Constructs the container with the contents of the range [first, last). This constructor does not participate in overload resolution if InputIt does not satisfy InputIterator, to avoid ambiguity with the overload 2 (since C++11)

Zgadza się to z projektu C++ 11 część standardowa 23.2.3kontenerów sekwencyjne ust który mówi:

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.

Powiązane problemy