-1
我试图找出如何能够写出这样的事:重载运算符<<用于打印自定义异常
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()' – Pubby 2013-04-07 00:33:17
为什么'c'标签? – 2013-04-07 00:33:44
@LightnessRacesinOrbit sry,我的错 – Dworza 2013-04-07 00:35:26