How do I return hundreds of values from a C++ function?

前端 未结 9 1465
无人共我
无人共我 2021-01-01 04:37

In C++, whenever a function creates many (hundreds or thousands of) values, I used to have the caller pass an array that my function then fills with the output values:

9条回答
  •  旧时难觅i
    2021-01-01 05:27

    You could return a smart pointer to a vector. That should work and no copy of the vector will be made.

    If you don't want to keep the smart pointer for the rest of your program, you could simply create a vector before calling the function, and swap both vectors.

提交回复
热议问题