In C++98 the prototype for std::vector
's fill constructor has a default value for the initializer:
explicit vector (size_type n, const value_type& val = value_type(),
const allocator_type& alloc = allocator_type());
In C++11 it becomes two prototypes:
explicit vector (size_type n);
vector (size_type n, const value_type& val,
const allocator_type& alloc = allocator_type());
(In C++14 the fill constructor changed again, but it's not the point of this question.)
My question is, why did C++11 deprecated the default initializer value value_type()
?
BTW: I tried with this code below in clang++ -std=c++11
and it issued an error, which means the value type still need to have a default constructor like S() {}
.
#include <vector>
struct S {
int k;
S(int k) : k(k) {}
};
int main() {
std::vector<S> s(5); // error: no matching constructor
}
Aucun commentaire:
Enregistrer un commentaire