失败返回为空,应该做个判断吗
失败返回为空,应该做个判断吗
失败返回为空,应该做个判断吗
2017-10-16
#include <iostream>
#include <string>
using namespace std;
string getName(string *name = 0 )
{
if(name == NULL)
{
throw string("请重新输入名字!");
}
else
{
return *name;
}
}
int main()
{
string a = "Jim";
try
{
getName();
//getName(&a);
cout << a << endl;
}
catch(string &e)
{
cout << e << endl;
}
return 0;
}举报