Enum定义在课堂上很重要 [英] Enum defintion matters in class

查看:79
本文介绍了Enum定义在课堂上很重要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

将Visual Studio 2015更新为Update 3后,我遇到了问题。我有 下面定义了两个A和B类。 B有一个默认参数的ctor。


I run into a problem after updating my visual studio 2015 to Update 3. I have  two classes A and B defined below. B has a ctor with default parameter.

class A { public: A(int idd) :i(idd) {} enum { IDD = 1 }; int i; }; class B : public A { public:

B(int idd = B :: IDD)
:A(idd)
{}
enum {IDD = 2};
};

int main()
{
B b = B();

返回0;
}

B(int idd = B::IDD) :A(idd) {} enum { IDD = 2 }; }; int main() { B b=B(); return 0; }


当在B类枚举定义位于ctor定义之后时,默认参数实际上是值1(A :: IDD)而不是2.

当我在ctor之前移动枚举定义时,默认参数是2,正如我预期的那样。

When in class B enum definition is located after ctor definition, default parameter has actually value 1 (A::IDD) instead of 2.

When I moved enum definition before the ctor, default parameter is 2 as I expected.

在Update 3之前,默认参数始终为2,无论它位于何处。

Before Update 3 default parameter was always 2 no matter where it was located.

感谢您的回答













推荐答案

On 6/27/2017 10:15 AM, ginCat写道:

On 6/27/2017 10:15 AM, ginCat wrote:


在更新3之前,默认参数始终为2,无论它位于何处。我找不到有关此编译器更改的任何信息 发行说明中的​​行为。根据C ++标准,这是正确的行为吗?

Before Update 3 default parameter was always 2 no matter where it was located.I couldn't find any information about this change of compiler  behavior in release notes. Is it correct behavior according to C++ standard?

对我来说看起来像个错误。我对标准的解读是bi应该是2. Clang和GCC都同意。

Looks like a bug to me. My reading of the standard is that b.i should be 2. Clang and GCC both agree.


这篇关于Enum定义在课堂上很重要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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