Quantcast
Channel: Active questions tagged return-value - Stack Overflow
Viewing all articles
Browse latest Browse all 210

Options for returning multiple types from a method

$
0
0

I want a method to alter multiple variables outside of it, which, if I understand correctly wouldn't/couldn't change outside the scope of that function, unless specifying and returning a specific type. I also know I can't return multiple types from a function.

struct multiTypes {    int i = 0;    float f = 1.0;    std::string a = "testing";};multiTypes test() {    multiTypes mT;    mT.i += 2;    return mT;}int main() {    std::cout << test().i << '\n';    std::cout << test().f << '\n';    std::cout << test().a << '\n';}

While this does work, I was wondering, what other alternatives exist to achieve the same result?


Viewing all articles
Browse latest Browse all 210

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>