错误C2536的解决方法:无法在Visual Studio 2013中为阵列指定显式初始化程序 [英] Workaround for error C2536: cannot specify explicit initializer for arrays in Visual Studio 2013

查看:3770
本文介绍了错误C2536的解决方法:无法在Visual Studio 2013中为阵列指定显式初始化程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码不能使用Visual Studio 2013编译,而应该:

the following code does not compile with Visual Studio 2013 while it should:

class A
{
    A() :m_array{ 0, 1, 2 } {} // error C2536: 'A::A::m_array' : cannot specify explicit initializer for arrays
private:
    int m_array[3];
};

请参阅错误报告了解详情。

strong>可能的解决方法是什么?

What are the possible workarounds?

推荐答案

>

As the comments, you can try this workaround.

class A
{
    A() : m_array ({ 0, 1, 2 }) {}
private:
    std::array<int, 3> m_array;
};

看起来VS2013为 std :: array 构造函数,你可以在构造函数的初始化中初始化它。你写的代码是有效的,gcc和clang都支持它。 VS2013缺乏。

It seems VS2013 made initializer-list for std::array constructor well and you can initialize it in constructor's intializer. The code that you wrote is valid and both gcc and clang support it. VS2013 lacks.

这篇关于错误C2536的解决方法:无法在Visual Studio 2013中为阵列指定显式初始化程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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