I am learning about classes and there are certain things I am not sure.
One of this is that I wanted to check, if I create a class for example CarDatabase. Inside I have ability to provide specific details about object such as brand, size, type of engine.
What is best way to store this?
Each object have different attributes which can be of any type, unique numbers such as weight, dimensions, size, colour etc.
how to keep this?
How this can be accessed if I want to list all red cars? or cars with 2 doors?
I hope I am not mixing this badly ;) and its fairly clear what I need :)
thanks for this, so we could keep data about car inside struct (details such as brand, weight, colour etc) but then would you use vector to all car objects, do you have to do that?
I am trying to put this in my mind,
I have class CARS
then I create objects and each object have its own attributes
Naming is important in OOP design. Notice Thomas1965 called the struct Car: because it is a solitary car. And the vector is cars because it is a collection of cars.
but then would you use vector to all car objects, do you have to do that?
No, but it makes more sense to do so, having a collection is better than having lots of individual objects. A collection is a sort of abstraction: we group like things together.
std::vector is a good choice for a container. Have a look at the documentation for it, one can push_back items into it.
thank for the explanation.
I done few exercises that involved vector I assumed that vector will keep (in similar way to array) would keep only one type of data like integer so I could store in index 0 weight 2000, in index 1 1500 and in index 3 5000KG which would represent three cars from above example VW - 2000KG, Mercedes, 1500KG and BMW 5000KG.
based on what i read in this post I think message is that vector will allow (through) struct to keep all attribiutes, colour, brand, weight etc...