I am still confused about the requirements for a type to be used with a std::vector
in C++11, but this may be caused by a buggy compiler (gcc 4.7.0). This code:
struct A {
A() : X(0) { std::cerr<<" A::A(); this="<<this<<'
'; }
int X;
};
int main()
{
std::vector<A> a;
a.resize(4);
}
works fine and produces the expected output, indicating that the default ctor (explicitly given) is called (and not an implicit copy ctor). However, if I add a deleted copy ctor to the class, viz
struct A {
A() : X(0) { std::cerr<<" A::A(); this="<<this<<'
'; }
A(A const&) = delete;
int X;
};
gcc 4.7.0 does not compile, but tries to use the deleted ctor. Is that correct behaviour or a bug? If the former, how to get the code working?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…