So I followed this SO answer for my purposes, and I really do not know how to resolve this error. When I try to access audioType[wav] or audioType[mp3], the error below comes up. Looking up the internet was not helpful for me.
error: no viable overloaded operator[] for type 'const std::map<AudioTypes, const char *>
note: candidate function not viable: 'this' argument has type 'const
std::map<AudioTypes, const char *>', but method is not marked const
mapped_type& operator[](const key_type& __k);
// WAVFile.h
class WAVFile {
// ...
private:
enum AudioTypes: int;
static std::map<AudioTypes, const char*> audioType;
// ...
}
// WAVFile.cpp
enum AudioTypes: int {
wav,
mp3
};
static map<AudioTypes, const char*> audioType = {
{wav, "wav"},
{mp3, "mp3"}
};
bool WAVFile::exportAudio(const char* filename, const char* filetype) {
// temporary test code
cout << audioType[wav] << endl;
return true;
}
// main.cpp
int main() {
file.exportAudio("export_i ran.wav","wav") ? cout << "Exported\n" : cout << "Failed\n";
return 0;
}