-2

I asked this question before but the suggestions don't work so I have tried to make my question more clear.

I have a function that returns a std::pair<int, double> but the parameters for the function as follow function(int g, double a);. This function then using make_pair to make a pair with the first being the int and the second being the double. It returns the pair.

I want to create another function to use the pair from the previous function and view the data in the pair, i.e. both first and second. Is it possible to pass the return of the previous function as a parameter for my new function so the second function can view the data? I am unsure about the syntax in C++.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
May
  • 15
  • 1
  • 1
  • 3

1 Answers1

1

It wouldn't be so hard if you rather not talked about the code but started trying to write it:

#include <iostream>
#include <utility>

std::pair<int, double> function(int g, double a)
{
    return std::make_pair(g, a); // or return {g, a};
}

void print(std::pair<int, double> pair) // or take by reference-to-const
{
    std::cout << pair.first << " " << pair.second << std::endl;
}

int main()
{
    print(function(4, 5.5));
    return 0;
}

Something's not in order if you're dealing with class templates, but don't know how to write functions.

LogicStuff
  • 19,397
  • 6
  • 54
  • 74