I have a member in my class defined like this inside my header file:
static const vector<note_name> noteMap;
In my source file I want to assign values to the vector so I tried:
const vector<note_name> AppSettings::noteMap = {...}
But I’m getting an error: Non-aggregate type 'const vector<note_name>' cannot be initialized with an initializer list. Any ideas how I could initialize this vector? Using an array is not an option btw.
Write a function that returns a
vector<note_name>with the appropriate values filled in, and use that function to initializenoteMap. That will always work; with more information about the initializers it might be possible to come up with a better solution. Or, if you have C++11, you can use an initializer list as in the example.Or, with TR1 or Boost or C++11, change the
vectorto anarray<note_name>. Thearraytemplate supports aggregate initialization.