Answer the question
In order to leave comments, you need to log in
When initializing an array of strings in an object, the error "too many initializers for 'String[0]'" appears. What could be the problem?
When initializing an array of strings inside an object, the error "too many initializers for 'String [0]'" occurs at the compilation stage and swears just at the array.
Moreover, if the same array is declared in the global space, then everything works.
Here is a sample code
class Colors
{
public:
// Список цветов
String colors[] = {
"#00ff0d",
"#b71c1c",
"#9c27b0",
"#fbc02d",
};
int _index = 1; // Текущий номер цвета
int _colorsSize = 0; // Количество цветов
String init()
{
}
String getColor() {
}
String nextColor() {
}
String prevColor() {
}
};
Answer the question
In order to leave comments, you need to log in
Because it is forbidden by the standard. Specify the size of the array, or use std::array.
I advise you to add the following compilation flags: -pedantic -Wall -Wextra.
String colors[4] = {
"#00ff0d",
"#b71c1c",
"#9c27b0",
"#fbc02d",
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question