Hey all,
So I've run into the most bizarre issue while trying to make a mod...
1. bz_PlayerDieEventData_V1 *data1 = static_cast<bz_PlayerDieEventData_V1 *>(ed);
2. bz_FlagGrabbedEventData_V1 *data2 = static_cast<bz_FlagGrabbedEventData_V1 *>(ed);
3. if (data1->flagKilledWith == "GK") {}
4. if (bz_getFlagName(data2->flagID) == "GK") {}
5. if (bz_ApiString("GK") == "GK") {}
I have these 5 lines of code. For some reason, line 4 fails in the compiler saying that "no match for operator== and operand types 'const bz_ApiString' and 'const char [3]'
However, the BZ API says that operator== has been overloaded for bz_ApiString and char*. Furthermore, lines 3 and 5 do not fail, which blatantly compares a bz_ApiString and char*.
What's going on here? There has to be some kind of data type I'm not recognizing, but I have no idea what.
Thanks,
Grue
Bizarre ApiString comparison error
Re: Bizarre ApiString comparison error
I’m a little rusty on my C++, but as you mentioned it does return a const bz_ApiString (notice the constant declaration), and the == operator overload in bz_ApiString is not declared constant (not sure if that matters or whether it affects visibility). Try assigning the return value to a variable first, or maybe you could cast away the constant aspect of it. Otherwise, I wonder if it’s some kind of lvalue versus rvalue issue, but that’s a bit above my level of knowledge.
Re: Bizarre ApiString comparison error
Wow, thank you so much!
That was my error. For the fix, I made a quick non-constant variable and assigned the constant value to it, and then just used the variable.
Thanks again,
Grue
That was my error. For the fix, I made a quick non-constant variable and assigned the constant value to it, and then just used the variable.
Thanks again,
Grue
Re: Bizarre ApiString comparison error
The plugin API is not const-correct at all. So it's hard to write const-correct code.