When I started working with C++, I put everything into one big .cpp file.
I'm now trying to change this by creating classes for my functions. But I encountered a problem.
I have a function where there's an index which is supposed to get raised by 1 under certain circumstances & keep this value for the next time. This index is used for renaming a file for example. Like this:
// if there's "motion" create new video file, reset index
if (numCont > 0 && contours.size() < 100) {
index = 0;
MotionDetector::saveFile(frame1, output_file, addFrames, video_nr);
}
// if there's a video file & no motion, raise index by 1
// if there's been no motion for x frames (that's what the index is for),
// stop recording
if (addFrames && numCont == 0) {
index++;
MotionDetector::saveFile(frame1, output_file, addFrames, video_nr);
if(index == 30) addFrames = false;
}
Inside of saveFile is something like this:
if (!addFrames) {
// release old video file
// create new file using video_nr for the naming part
}
else {
//add frame to existing video
video << frame;
}
Another variable I want to change "globally" is a boolean. If certain conditions are met it is either true or false and this state has to be saved for the next time the function gets called.
I know that I could return the values and then use it from my main again BUT then I'd have ~3 different variables (one Mat, one int, one bool) to return and I have no idea how to handle that.
Before I moved it to its own class I still had 2 variables to make it work, even though I kinda got to the point of thinking it was quite useless that way. Is there any easy way to keep changes made by functions in external classes? Tried it using reference already, but it didn't seem to work either.
Right now addFrames is a referenced argument passed from the original class/function-call but it doesn't work as intended.