-1
我想從一個布爾函數返回多個值,但我得到了「分段錯誤(核心轉儲)」錯誤。我的代碼是布爾返回很多值
#include<iostream>
using namespace std;
bool te(int b,int *c,int *e){
if (b>5){
*c=68;
return true;
}
else {
*e=69;
return false;
}
}
int main() {
int y;
int *z;
int *r;
cout<<"Give number:"<<endl;
cin>>y;
if(te(y,z,r)==1) {
cout<<"b is >5"<<endl;
cout<<*z<<endl;
}
else {
cout<<"b is <5"<<endl;
cout<<*r<<endl;
}
return 0;
}
它的工作原理如果bool = false,但在bool = true時出現分段錯誤。
使用引用或返回'的std :: tuple'。或者你的自定義對象。 – LogicStuff