Why don't std::vector's elements need a default constructor?

前端 未结 4 1533
失恋的感觉
失恋的感觉 2020-12-02 23:22

And how can I write my own array class to not need a default constructor for its elements? Right now, when I do the new [] to allocate space, I need a default const

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 23:52

    For me the std::vector was requiring a default constructor for my class (say T) because I was calling resize() method of the vector, despite I was only calling the method to shrink the vector, but never to grow.

提交回复
热议问题