c++ - Two functions variables in to a single function -
i have 2 variables in 2 different functions, i'd store them in third function without using global variables. how it?
something this
void function1() {    = 1;   b = 2; }  void function2() {   c = 3;   d = 4; }  void function3 () {   cout << a;     cout << b;     cout << c;     cout << d;   }      
your functions can return values can pass variables other functions, so
std::pair<int, int> function1() {     int = 1;     int b = 2;     return {a, b}; }  std::pair<int, int> function2() {     int c = 3;     int d = 4;     return {c, d}; }  void function3 () {     int a, b, c, d;     std::tie(a, b) = function1();     std::tie(c, d) = function2();     std::cout << a;       std::cout << b;       std::cout << c;       std::cout << d;   }        
Comments
Post a Comment