【发布时间】:2013-04-07 00:31:49
【问题描述】:
我正在尝试找出如何能够写出这样的东西:
try{
throw MyCustomException;
}
catch(const MyCustomException &e){
cout<< e;
}
但是如何为此目的定义overloaded operator <<?
自定义异常类:
class MyCustomException{
public:
MyCustomException(const int& x) {
stringstream ss;
ss << x;
msg_ = "Invalid index [" + ss.str() + "]";
}
string getMessage() const {
return (msg_);
}
private:
string msg_;
};
【问题讨论】:
-
IMO 只做
cout << e.getMessage() -
@LightnessRacesinOrbit 对不起,我的错误
标签: c++