C++ ---Return multiple values of different types

we usually use functions that return one or no return value.

  • More than one different type of return value was recently returned on a project.

  • You can use vector to return multiple parameters of the same type.

  • If you can use the C++11 standard, you can use my method below

(1)import the header file.

#include <tuple>
using namespace std;

(2)defined function,you can refer to the following code:

std::tuple<vector<Mat>, bool,Mat, bool,bool,bool,bool,bool,Mat,Mat,int> Table_Detection(Mat srcImage,double firstblackline_rows_ratio_thresh,bool isHorizonLine,double left_right_cols_ratio_thresh,double up_down_rows_ratio_thresh,Mat srcImageBin);

(3)function,you can refer to the following code:The type returned should be the same as the defined type.

std::tuple<vector<Mat>, bool,Mat, bool,bool,bool,bool,bool,Mat,Mat,int> Table_Detection(Mat srcImage,double firstblackline_rows_ratio_thresh,bool isHorizonLine,double left_right_cols_ratio_thresh,double up_down_rows_ratio_thresh,Mat srcImageBin)
{
;
return std::make_tuple(CUT_Table,table_new,Page_Info,isHorizonLine,table_new_cut,istablerecognition,Integrity_Check_Bottom,Integrity_Check_Top,Bottom_Integrity,Top_Integrity,tablesize);
}

(4)Now,you can call the return value.you can refer to the following code:Define a variable to receive the return parameter,the following code defines is the same as the define function.

std::tuple<vector<Mat>, bool,Mat, bool,bool,bool,bool,bool,Mat,Mat,int> data;

You also can use the auto to define.Auto is an adaptive variable in the C++11 standard.

auto data;

You can use the get method to get the data.you can refer to the following code.The code of the get<0>data actually get is CUT_Table.

std::get<0>(data);
std::get<1>(data);
std::get<2>(data);

I hope I can help you,If you have any questions, please  comment on this blog or send me a private message. I will reply in my free time.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值