Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue: Unable to Use [] Operator on mINI::INIStructure Parameter in Function #41

Open
aghaeifar opened this issue Dec 27, 2024 · 1 comment

Comments

@aghaeifar
Copy link

Hi,

I am encountering an issue when working with the mINI::INIStructure type in a function. Here is the scenario:

I read my .ini file in main.cpp as follows:

mINI::INIFile file(config_file);
mINI::INIStructure ini;
if (!file.read(ini)) {
    std::cout << "Failed to read config file: " << config_file << "\n";
    return 1;
}

Later, I have a function that accepts a mINI::INIStructure object as a parameter:

void my_func(mINI::INIStructure ini)

Inside this function, I cannot use the [] operator on the ini parameter. When I try to access the structure like this:

ini["GENERAL"]["work_dir"];

It results in a compilation error. However, using the .get method works without any issues:

ini.get("GENERAL").get("work_dir");

Compiler Error:

error C2678: binary '[': no operator found which takes a left-hand operand of type 'const mINI::INIStructure' (or there is no acceptable conversion)

My Question:

Is this behavior expected? Or is there something I am doing incorrectly?

Thank you for your help!

@metayeti
Copy link
Owner

metayeti commented Dec 27, 2024

Your function should accept (mINI::INIStructure& ini) or (mINI::INIStructure const&), so you're dealing with the reference rather than a copy. Or I believe at the very least it should accept a (const mINI::INIStructure). Definitely something to look into for future versions though, so thanks for bringing this to my attention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants