Im trying to compile but im getting these errors:
1>.\item.cpp(123) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
1>.\commands.cpp(1372) : error C2057: expected constant expression
1>.\commands.cpp(1372) : error C2466: cannot allocate an array of constant size 0
1>.\commands.cpp(1372) : error C2133: 'buffer' : unknown size
Line 123 item.cpp
if((bool)random_range(0, 1))
Line 1372 commands.cpp
if(money < changeSexPrice)
{
char buffer[70 + changeSexPrice];
sprintf(buffer, "You do not have enough money. You need %d gold coins to change your sex.", changeSexPrice);
player->sendCancel(buffer);
return false;
}
any idea?
Your problem is
char buffer[70 + changeSexPrice];. win32 compilers need a constant expression when doing stack allocation.I’m not sure why you’re adding changeSexPrice as you are only using the buffer to print an int. I bet if you pick a something like
char buffer[1024]then you will have more than enough for your needs.EDIT: Per the comments (which are very good).
If you use a fixed size buffer of len 1024, use snprintf. In Visual Studio’s case, this is sprintf_s. Your code would change to:
Alternatively, Mark B presents an answer that removes the need for your own mem allocation as well.