Error: cannot indicate explicit initializer for array

I am using Visual Studios 2013 and I keep getting this error, but I donโ€™t understand why.

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

Mistake:

 error C2536: 'CLI::CLI::commands': cannot specify explicit initializer for arrays 
+8
c ++ arrays c ++ 11 visual-studio-2013
source share
2 answers

Visual Studio 2013 is not fully compatible with C ++ 11, so, as Tobias Brandt said, you will need to use a constructor to initialize these members.

Braced initialization lists are a C ++ 11 feature.

+14
source share

I do not think that class initializers in the class are implemented in VC2013. Initialize the array in the constructor instead. For example:

 class CLI{ string commands[2]; public: CLI() : commands {"create", "login"} {} }; 
+2
source share

All Articles