错误:无法为数组指定显式初始值设定项 [英] Error: cannot specify explicit initializer for array

查看:33
本文介绍了错误:无法为数组指定显式初始值设定项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Visual Studios 2013 并且不断收到此错误,但我不明白为什么.

I'm using Visual Studios 2013 and I keep getting this error yet I don't understand why.

class CLI{
    string commands[2] = {"create", "login"};
public:
    void addCommand(), start(), getCommand(string);
};

错误:

error C2536: 'CLI::CLI::commands': cannot specify explicit initializer for arrays

推荐答案

Visual Studio 2013 并不完全符合 C++11,因此,正如 Tobias Brandt 所说,您需要使用构造函数来初始化这些成员.

Visual Studio 2013 is not completely C++11 compliant, so, like Tobias Brandt said, you'll need to use a constructor to initialize those members.

花括号初始化列表是 C++11 的特性.

Braced init lists are a C++11 feature.

这篇关于错误:无法为数组指定显式初始值设定项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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