What does string array[] = ""; mean and why does it work?
arrays, c++
Solution
This is incorrect code; it is a bug in your compiler (possibly gcc/g++?) to accept it.
clang gives the following error (link):
a.cpp:5:17: error: array initializer must be an initializer list
std::string array[] = "";
^
1 error generated.
Visual C++ agrees (link):
testvc.cpp(2) : error C3074: an array can only be initialized with an initializer-list
The relevant clause in the standard is 8.5p17:
[...] — If the destination type is an array of characters, an array of char16_t, an array of char32_t, or an array of wchar_t, and the initializer is a string literal, see 8.5.2. [...] — Otherwise, if the destination type is an array, the program is ill-formed. [...]
Submitted to gcc as a bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60009
Problem
``` string array[] = ""; ``` How am I able to assign a `const char*` to an array? Is that the same as: ``` string array[] = {""}; ``` ?? That would make sense to me. However, this still doesn't work ``` int array[] = 5; ``` So what is the difference between them that it doesn't work for `int` arrays?