I believe this could be a duplicate just because I don't knwo what exact terms should I use to google for the right thing.
I'm working with Arduino and I've written library for communication between multiple Arduinos and Raspberries.
class Machine {
public:
// other functions here
Mission & create_mission(int num);
private:
// other variables here
Mission _missions[10];
};
And here is the class implementation:
Mission & Machine::create_mission(int num) {
Mission mission = Mission();
mission.setNumber(num);
_missions[_missions_count] = mission;
_missions_count += 1;
return _missions[_missions_count-1];
}
As I understand, this:
mission1 = machine.create_mission(1);
does not point to the same mission in _missions array within the class Machine. As I'm not experienced in c++, the question is - how should I implement the function to return the same Mission that's inside the _missions array?
The full code can be downloaded here (.zip): riddle.lv/code/code.zip
std::array<Mission, 10>?Mission & create_mission(int num)and in definition, you haveMission Machine::create_mission(int num)(missing reference).mission.