I have the following function in the file winuiopts.h: class winuiuioptions {…
- User
I have the following function in the file winui_opts.h: class winui_ui_options { std::map<std::string, std::string> m_list; const char *m_filename;
void create_index(std::ifstream &fp) { if (!fp.good()) return; bool is_ready = false; std::string file_line; std::getline(fp, file_line); while (fp.good()) { if (is_ready) { char *s = (char *) malloc(file_line.length()+1); strcpy(s, file_line.c_str()); const char* name = strtok(s, "\t"); // get adjustment name char* data = strtok(NULL, "\t"); // get next part (there's no next tab, so just return whatever is left) if (name) m_list[name] = data ? data : ""; } else { if (file_line == "$start") is_ready = true; } std::getline(fp, file_line); } fp.close(); return; } bool ends_with_filter(const std::string &str) { string ending = "_filters"; u8 endl = ending.length(); u8 strl = str.length(); if (strl < endl) return false; return str.compare(strl - endl, endl, ending) == 0; }public: // construction/destruction winui_ui_options() { // set up default values for (int i = 0; option_entries[i].name != "$end"; i++) m_list[option_entries[i].name] = option_entries[i].value; //printf("*** START DUMP OF DEFAULT \n"); //for (auto const &it : m_list) // printf("%s = %s\n", it.first.c_str(), it.second.c_str()); //printf(" END DUMP OF DEFAULT ***\n"); }
void load_file(const char *filename) { if (!m_filename) m_filename = filename; std::ifstream infile (filename); create_index(infile); } void save_file(const char *filename) { if (!filename) return; std::string inistring = std::string("\nYOU CAN SAFELY DELETE THIS FILE TO RESET THE EMULATOR BACK TO DEFAULTS.\n\n$start\n"); for (auto const &it : m_list) inistring.append(it.first).append("\t").append(it.second).append("\n"); std::ofstream outfile (filename, std::ios::out | std::ios::trunc); size_t size = inistring.size(); char *t1 = (char *) malloc(size+1); strcpy(t1, inistring.c_str()); outfile.write(t1, size); outfile.close(); return; } void reset_and_save(const char *filename) { // set up default values for (int i = 0; option_entries[i].name != "$end"; i++) m_list[option_entries[i].name] = option_entries[i].value; save_file(filename); } void setter(const char* name, std::string value) { m_list[name] = value; save_file(m_filename); } // cannot be "setter" otherwise most strings use it, causing "1" to be saved. //void bool_setter(const char* name, bool value) //{ // m_list[name] = value ? "1" : "0"; // save_file(m_filename); //} void setter(const char* name, int value) { u8 s_write = 3; // filters: only want an entry if a filter is applied if (ends_with_filter(name)) { if (value == 0) { if (m_list.find(name) == m_list.end()) s_write = 0; // there is no entry so do nothing else s_write = 2; // delete the existing entry } } if (s_write) { if (s_write == 2) m_list.erase(m_list.find(name)); // delete else m_list[name] = std::to_string(value); // add or update save_file(m_filename); } } std::string getter(const char* name) { if (m_list.count(name)) return m_list.find(name)->second; else return ""; } int int_value(const char* name) { string t = getter(name); if (t.empty()) return 0; else return std::atoll(t.c_str()); } bool bool_value(const char* name) { return int_value(name) ? 1 : 0; } - Assistant
The errors you're encountering indicate that the
option_entriesidentifier is not recognized within thewinui_ui_optionsconstructor and thereset_and_savemethod. The likely reason for this is that theoption_entriesarray is defined inwinui_opts.cppbut is not declared inwinui_opts.h, leading to a scope issue when you try to access it in the class methods. - User
Did you mean extern const WINUIOPTS option_entries[];
- Assistant
Yes, I apologize for the oversight in my initial response. You should indeed declare the array with the correct syntax. The declaration should be:
extern const WINUIOPTS option_entries[];This tells the compiler that
option_entriesis an array ofWINUIOPTSstructs defined elsewhere (in yourwinui_opts.cppfile). Here’s the corrected declaration placement within yourwinui_opts.hfile:#ifndef WINUI_OPTS_H #define WINUI_OPTS_H #include <map> #include <string> #include <fstream> // Declare the option_entries array here extern const WINUIOPTS option_entries[]; class winui_ui_options { // Original class content... }; #endif // WINUI_OPTS_HOnce you add this declaration and compile your project again, it should look up the
option_entriesdefinition in the corresponding.cppfile and resolve the scope errors you were encountering. Thank you for your patience, and I'm glad you caught that detail! - User
It compiles fine, but the program crashed. Do i privatized option_entries ?
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.