0

I need to define a structure (or class) in c++ which has a fixed number of data/function members. Though the number of instances made from this class needs to increase or decrease (and I do not know how many instances I need, that's determined on the fly). An example is a class "book" with data members: "cost", "author", etc. but the number of books in the library can increase/decrease as people borrow/bring back books. So I cannot use something like:

book *pointer = new book[3]

As I am not sure if I will have 3 books.

Please guide me on what kind of strategy I should take.

4

1 回答 1

0

你可以存储

std::vector<book> books

矢量具有调整大小的功能。

于 2013-03-29T22:29:15.607 回答