我可以从函数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