我的意思是这样的
#include <iostream>
using namespace std;
class A{
int a, b;
public:
A(int a,int b, int *c);
};
A::A(int x, int y, int *errcode)
{
*errcode = 0;
a=x;
b=y;
// check for some error conditions
// and return from the constructor
if (y==0)
{
*errcode=-1;
return;
}
// some more operations
return;
}
int main() {
int errorcode;
A(1,0,&errorcode);
cout << errorcode;
return 0;
}
Run Code Online (Sandbox Code Playgroud)