문제

Since VS2008 the class bad_alloc does not provide a constructor with string parameter. Is there any possibility to create a custom message without overwriting the class like this?

// this is only pseudo-code
class custom_exception : bad_alloc {
public:
    string Message;
    custom_exception(string m) {Message = m;}
}
도움이 되었습니까?

해결책

bad_alloc needs to be constructible without allocating memory, which is why its constructor does not take a message parameter. You can of course subclass it and override what.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top