Setting <Arduino.h> static const String variables inside classes

  arduino-c++, c++

I’m trying to define a static const String variable, String doesn’t exist in C++ standard but is allowed here with the Arduino.h.

So giving the specificity of String type how can I make it a constant too in the following header file.

#ifndef CHORDSBOX_H_INCLUDED
#define CHORDSBOX_H_INCLUDED

#include <Arduino.h>

class ChordsKey {
    private:
        static const int i = 4;
        static const String notes_name[] = {"C ", "C#", "D ", "D#", "E ", "F ", "F#", "G ", "G#", "A ", "A#", "B "};

        static const String scales_name[] = {"Major", "Dorian", "Phrygian", "Lydian", "Mixolydian", "minor", "Locrian",
                                             "Diminished", "Augmented"};
    public:
        void SetChords();
};

#endif // CHORDSBOX_H_INCLUDED

It returns error "a member of type "const String []" cannot have an in-class initializer" for both String declarations.

How can I declare those static variables?

Thanks

Source: Windows Questions C++

LEAVE A COMMENT