Return value in infinite loop

Hello!

I'm currently trying to work with some image processing.

I'm using a function that streams the camera captions with an infinite while loop.

I just wanted to know, if it was possible to make the captions a return value of the function. I've tried to use "return" but it immediately kills the task.

In other words, make a function constantly have a return value by being called just once.

Thanks for your time, any reference would be of big help!

-Fernanda
Last edited on
If a function returns a value then it finishes executing and must be called again to restart, and a function cannot send data back to the caller without returning.

Maybe what you want is for the function to continue running while a different function is also running and processing the data that was previously obtained. That's what threads are for. You can use them to execute multiple functions concurrently (i.e. "at the same time").
Maybe a callback might be an option.
1
2
3
4
5
6
7
8
9
10
11
12
template<class Callback>
some_value work(Callback callback)
{
  while (true)
  {
    // if some result available
    callback(/* pass the data to the caller*/)

    if(some condition)
      return some value;
  }
}
Thanks for the answers! i've tried to implement your approach and it worked :].

I'm grateful, have a nice day!

-Fernanda
Topic archived. No new replies allowed.