Bizarre ApiString comparison error

Questions, comments, and news on the server side plug-ins and it's API
Post Reply
Grue
Private First Class
Private First Class
Posts: 27
Joined: Tue Apr 08, 2014 12:23 am
Contact:

Bizarre ApiString comparison error

Post by Grue »

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
User avatar
macsforme
General
General
Posts: 2069
Joined: Wed Mar 01, 2006 5:43 am

Re: Bizarre ApiString comparison error

Post by macsforme »

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.
Grue
Private First Class
Private First Class
Posts: 27
Joined: Tue Apr 08, 2014 12:23 am
Contact:

Re: Bizarre ApiString comparison error

Post by Grue »

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
Enigma
Private First Class
Private First Class
Posts: 212
Joined: Sat Apr 23, 2005 3:13 am

Re: Bizarre ApiString comparison error

Post by Enigma »

The plugin API is not const-correct at all. So it's hard to write const-correct code.
Post Reply