为什么std :: exception在VC ++中有额外的构造函数? [英] Why does std::exception have extra constructors in VC++?

查看:174
本文介绍了为什么std :: exception在VC ++中有额外的构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚注意到了。在例外 >标准(18.6.1):

Something I noticed just now. Definition of exception in the standard (18.6.1):

class exception {
public :
    exception() throw();
    exception(const exception &) throw();
    exception& operator=(const exception&) throw();
    virtual ~exception() throw();
    virtual const char* what() const throw();
};

中的定义MSDN :

Definition of exception in MSDN:

class exception {
public:
   exception(); 
   exception(const char *const&);
   exception(const char *const&, int);
   exception(const exception&); 
   exception& operator=(const exception&); 
   virtual ~exception();
   virtual const char *what() const;
};

看来Microsoft的版本允许你指定异常对象,而标准版本只允许您为派生类执行此操作(但不会阻止您创建一个通用的异常未定义的消息)。

It would seem that Microsoft's version allows you to specify the error message for an exception object, while the standard version only lets you do that for the derived classes (but doesn't prevent you from creating a generic exception with an undefined message).

我知道这是非常微不足道,但仍然。这是有很好的理由吗?

I know this is pretty insignificant, but still. Is there a good reason for this?

推荐答案

真的没有什么好的理由。 MS实现已经选择将字符串处理放在std :: exception而不是从它派生的每个类中(< stdexcept>)。

Not really any good reason. The MS implementation has chosen to put the string handling in std::exception instead of in each class derived from it (<stdexcept>).

因为他们实际上也提供标准所需的接口,这可以被看作是一个合格的扩展。

As they actually also provide the interface required by the standard, this can be seen as a conforming extension. Programs following the standard works as expected.

其他实现不这样做,因此可移植程序不应该使用额外的构造函数。

Other implementations do not do it this way, so portable programs should not use the extra constructors.

这篇关于为什么std :: exception在VC ++中有额外的构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆