Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
由于 VS2008 类 bad_alloc 不提供带有字符串参数的构造函数。有没有可能在不覆盖这样的类的情况下创建自定义消息?
// this is only pseudo-code class custom_exception : bad_alloc { public: string Message; custom_exception(string m) {Message = m;} }
bad_alloc需要在不分配内存的情况下可构造,这就是为什么它的构造函数不带消息参数的原因。您当然可以将其子类化并覆盖what。
bad_alloc
what