我可以從函數one intiger和boolean返回兩個值嗎?我試圖用這種方式做到這一點,但它不起作用。從C++中的一個函數返回兩個值
int fun(int &x, int &c, bool &m){
if(x*c >20){
return x*c;
m= true;
}else{
return x+c;
m= false;
}
fun(x, c, m);
if(m) cout<<"returned true";
else cout<<"returned false";
}
您只能從函數返回一個對象,但該對象可以是任意複雜的類型。 – juanchopanza
你可以使用'std :: tuple'。 – Simple