Quote:
Originally Posted by Dahakon
invalid conversion from const char* to char*
|
Code:
char *lap = local_argument;
Code:
lap = first_arg( lap, arg2, FALSE );
Code:
const char *first_arg( char *argument, char *arg_first, bool fCase )
first_arg() returns a
const char* but lap is a
char*. That is the error.
I don't know which would be easiest to change.
You seem to be using char* in several places where const char* would be more correct. For example, it looks like first_arg() modifies the characters pointed to by arg_first, but not those pointed to by argument. So it might be more correct if it were declared as
Code:
const char *first_arg( const char *argument, char *arg_first, bool fCase )
Then, you didn't show where else lap is used, so with that change to first_arg() you might fix the error by making lap const as well
Code:
const char *lap = local_argument;
But depending on how lap is used elsewhere, that might cause further problems.
Sometimes the only way to work with existing code, in which the const / non const choices have not been made carefully, is to cheat. You can hide the error from the compiler with a const_cast. Just change the problem lines for example:
Code:
lap = const_cast<char*>( first_arg( lap, arg2, FALSE ) );
If the code was logically correct and just had errors in where const was used or omitted, that will stop the compiler from caring the error and get you past the problem quickly. Use such cheating with care: It may confuse you later and make other bugs harder to diagnose.