Extending std::list

后端 未结 8 2121
小蘑菇
小蘑菇 2021-01-31 13:00

I need to use lists for my program and needed to decide if I use std::vector or std::list. The problem with vector is that there is no remove method and with list that there is

8条回答
  •  南方客
    南方客 (楼主)
    2021-01-31 13:29

    The obvious stuff has already been described in details:

    But the methods you choose to implement??

    • Destructor.
      • Not required compiler will generate that for you.
    • The two different versions of operator[] are pointless
      • Also you should be uisng std::list::size_type as the index
      • Unless you intend to support negative indexes.
    • There are no const versions of operator[]
    • If you are going to implement [] you should also do at()
    • You missed out all the different ways of constructing a list.
    • Containers should define several types internally
      • see http://www.sgi.com/tech/stl/Container.html

提交回复
热议问题