我有一个问题,这是我最近发布的其他两个问题的扩展:
和
假设我有一个数组A.我想创建一个功能f作用于A并返回其他两个数组B,并C通过启用以下Matlab的语法类似
[B,C]=f(A);
Run Code Online (Sandbox Code Playgroud)
在C++中有可能吗?
解决以下问题的解决方案
#include <tuple>
using std::tie;
std::tuple<TypeOfB,TypeOfC> f(const Matrix<T1>&a,const Matrix<T2>&a) {
// Instruction declaring and defining B_temp and C_temp
return std::make_tuple(B_temp,C_temp); }
int main( int argc, char** argv)
{
// Instruction declaring A, B and C
tie(B,C)=f(A);
// STUFF
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当改变一切正常,也std::tuple并make_tuple以std::pair和std::make_pair为这种特殊情况下(只有两个输出).