Reputation: 171
I was given a C++ assignment and I'm trying to understand the material before the actual coding process. I'm requested to simulate a "store" that can sell products, receive orders, manage inventory etc. I also need to implement a database to log every sale. I have to implement it with a Template class that will actually be dynamic array. The actual strategy that I have to achieve is two arrays(one twice the size of the other) and when the smaller one is full - the bigger is half-full, so i delete the smaller and create a new one - twice as big of the other array and so on.
My questions: Is there a real reason for Template here? or is it just for practicing? I can't see where would I be using the Template as a generic form?
Maybe someone knows of a good relevant link with explanation and/or example.
Upvotes: 0
Views: 266
Reputation: 73473
I guess you need to store an array of products, orders etc. In that case you can use your generic array class and create different instantiation of the template like Array<Product>
and Array<Order>
. In this way you can reuse the array code instead of writing different array class for each one of them.
Upvotes: 2