This was the code for your in_ov function:
Code:
void autoreg::in_ov(vehicle v,owner p)
{
vehicles vh;
ovmap ovm;
owners odata;
long id=p.getid();
string lic=vh.getlicense();
odata.insert(make_pair(id,p));
vh.insert(make_pair(lic,v));
ovm.insert(make_pair(id,lic));
}
The bold parts are the variable declarations. You are declaring the variables inside this function. It is the same as doing:
Code:
void print_one_to_ten()
{
int number = 1;
while (number < 10)
std::cout << number << ", ";
std::cout << number << '\n';
}
The variable number in that code is local to the function, so when the function ends it goes away. If you call the function again it creates a new variable and runs the function, it doesn't use the previous one. Variables declared inside a block of code are local to that block, and they are destroyed when that block of code ends.
In your case, you want the maps to stick around as long as your class object sticks around. For example, let's say you have a car class that has a headlight member. You want the headlights to stick around for as long as the car sticks around. If somebody turns the headlights on, then you want to remember that the headlights are on. If you create headlights local to the function and turn those on, then when the function ends the headlights will be destroyed. If somebody checks the headlights they will be off because the headlights that were on were destroyed.
If you make the variables member variables, then they live as long as the class itself, and anything you change about them is remembered. So when you add a new vehicle to the map when it is a member variable, the vehicle will still be there later when you call another function to get or change that data.