提问者:小点点

从函数C++[duplicate]返回3个元素



共1个答案

匿名用户

您可以编写一个包含3ints的结构,并从函数返回:

struct data
{
 int low, mid, high;
};

data fun( /* args ... */ )
{
  // ...
  return {low, mid, high};  
}

或者,如果您不想显式地命名该结构,您可以只返回一个包含3intstd::tuple

std::tuple<int, int, int> fun( /* args ... */ )
{
  // ...
  return {low, mid, high};  
}

无论哪种情况,您都可以在呼叫站点上写:

auto [low, mid, high] = fun();

相关问题


MySQL Query : SELECT * FROM v9_ask_question WHERE 1=1 AND question regexp '(函数|c++|duplicate|返回|3个|元素)' ORDER BY qid DESC LIMIT 20
MySQL Error : Got error 'repetition-operator operand invalid' from regexp
MySQL Errno : 1139
Message : Got error 'repetition-operator operand invalid' from regexp
Need Help?