I've got a class which contains these vectors:
class MainMenu {
private:
std::vector <Car> vehicles;
std::vector <Instructor> instructors;
std::vector <Trainee> trainees;
std::vector <Lesson> lessons;
public:
std::vector<Car>& getVehicles();
std::vector<Instructor>& getInstructors();
std::vector<Trainee>& getTrainees();
std::vector<Lesson>& getLesson();
}
//-------------------------------------------------
class Car : public Vehicle {
public:
static MARKA convertStringToMarka(std::string name);
Car(std::string numberPlate, MARKA marka, bool roadWorthy);
Car() {};
Car(int id,std::string numberPlate, MARKA marka, bool roadWorthy);
};
And somewhere in the code i perform such function:
Car *car = mainMenu.searchForCarById(idOfVehicle);
Car* MainMenu::searchForCarById(int id) {
for (Car elem : vehicles) {
if (elem.getIdInSystem() == id) {
return &elem;
}
}
}
While debugging i perform this code step by step, and this simply function search for car's correctly but whenever I return from funtion, every variable which was string dissapear. For example in name
variable I recieve ""
. I think it is important to mention that only strings dissapear! int stays as it was. What am i doing wrong?