I need a method that returns an array of enums and I tried:
note_name *AppSettings::getNoteMap(){
note_name notes[] = {..}
}
I read somewhere on SO that I’m supposed to return the address of the first element of the array, so that’s why there’s a pointer. This is giving me a warning though: address of stack memory associated with local variable notes returned
How do I get rid of the warning and return the array properly?
You cannot return an array from a function, period. You can return a pointer to a dynamically allocated chunk of memory (I wouldn’t go this route), or take a pointer (along with the size) as an output argument, or return a pointer to a static array, or return a
vector<T>or some other collection.I would use a
std::vectoror astd::array.