char * message;
string theMessage;
在C++中字符指针可以直接赋值给字符串,但在C中为错
例如:
char * message = “ define char * message ”;
string theMessage = message;
在函数中的应用,函数参数为字符指针
用字符串初始化字符指针,并把字符指针赋值给字符串
class illegalParameterValue
{
public:
illegalParameterValue ( char * message )
{ theMessage = message;}
~illegalParameterValue();
void outputMessage()
{ cout << e.theMessage;}
private:
string theMessage;
};
int func (int value)
{if(value < 0)
throw illegalParamaterValue("parameters should > 0");
return value;
}
int main()
{
try
{ func (-3);}
catch (illegalParameterValue e)
{
e.output();
}
return 1;
}