std::vector works with classes that are not default constructible?

前端 未结 4 730
醉话见心
醉话见心 2021-02-14 01:36

I\'ve read in several places that std::vector requires it\'s template argument to be default constructible. Today I just tried it with one of my classes that has a delete<

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-14 02:00

    There are two vector members that require a default constructible T in C++11:

    explicit vector(size_type n);
    void resize(size_type sz);
    

    Nothing else does. So if you use these signatures, you need to have a default constructible type, else you do not.

提交回复
热议问题