C++ vector with dynamic item size

前端 未结 9 2240
无人及你
无人及你 2021-01-14 16:54

the C++ STL vector has a lot of decent properties, but only works when the size of each item is known at run-time.

I would like to have a vector class that features

9条回答
  •  鱼传尺愫
    2021-01-14 17:23

    The problem is that if you don't have a way to store the size of each item in the vector you'll never be able to get the data back out.

    What about just storing ALL the items as double? This drastically simplifies things.

    Alternately you could consider boost::variant.

    EDIT: But really can you explain further why you want to store two different types in the same sequence? That can sometimes indicate that the underlying design needs further thought.

提交回复
热议问题