An API function takes an argument of type 'char *const argv[]' I am initializing this type of arguments in my c++ application like:
char* const argv[] = {"--timeout=0", NULL};
and passing the arguments to API function like:
Spawner spawner;
spawner.execute (argv, true);
using g++ compiler, I am getting following Error:
error: deprecated conversion from string constant to 'char*' [-Werror=write-strings]
how can I get rid of above error?
Below is the declaration of execute function in API:
void Spawner::execute (char *const argv[], bool bShowChildWindow)
Yeah, C++ is annoyingly (but correctly) strict about const chars. Try this
char timeoutString[] = "--timeout=0"; // make a non-const char array
char *argv[] = { timeoutString, NULL };
Spawner spawner;
spawner.execute( argv, true );
Technically, the problem is with the declaration of the execute method, which should be
void Spawner::execute (const char *const argv[], bool bShowChildWindow)
assuming execute doesn't modify the strings or the array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With