well, the standard says logic_error's interface is like this: class logic_error : public exception { public: explicit logic_error(const string& __arg); } hard to imagine an implementation that can actually avoid copying __arg. can you?
t*t
6 楼
no, i can't explain now. hehe.
【在 r*********r 的大作中提到】 : well, the standard says logic_error's interface is like this: : class logic_error : public exception : { : public: : explicit logic_error(const string& __arg); : } : hard to imagine an implementation that can actually avoid copying __arg. : can you? :
r*r
7 楼
i came up with an idea: define a char * data member x; and do the following in the constructor: x = (char *)malloc(__arg.size()); strcpy(x, __arg.c_str()); and return x in what(), and call free(x) in the destructor. maybe that works, at least it's guaranteed that no additional exception will be thrown.