Why don’t list or array have a capacity member
belongs to book: C++ Primer|Stanley B.Lippman, Josee Lajoie, Barbara E.Moo|5th Edition| Chapter number:9| Question number:37
All Answers
total answers (1)
belongs to book: C++ Primer|Stanley B.Lippman, Josee Lajoie, Barbara E.Moo|5th Edition| Chapter number:9| Question number:37
total answers (1)
A
`list`does not support random access, and element of`list`is stored seperately in memory. There is no need to reallocate its elements, and thus no need to preallocate memory. So the "`capacity`" of a`list`is the same with its`size`.An
`array`has a fixed size, there is also no need to reallocate its elements, and thus no need to preallocate memory. So the "`capacity`" of an`array`is the same with its`size`too.
need an explanation for this answer? contact us directly to get an explanation for this answer