i have read lot subject , confused .
what used work in c
file ,not working on cpp
file :
char *builtinfunctions[20];
then error on strcpy function here :
void intepreter::setbuiltins(char *builtins) { strcpy(builtinfunctions, builtins); // no matching function call strcpy }
i don't understand basics here, why in c++ not work ( need use = instead ? )
strcpy(char *, const char*) = thats structure
if change builtinfunctions
being pointer works.
edit: reason being const before edit read here : why conversion string constant 'char*' valid in c invalid in c++
that char *builtinfunctions[20];
produce warning when :
builtinfunctions[0]="me";
and did. fix removing const .
this array of pointers char.
char *builtinfunctions[20];
so call
strcpy(builtinfunctions, builtins);
gets treated strcpy(char **, char*)
, not strcpy(char *dest, const char *src)
. mismatch first parameter type.
edit:
so let's suppose builtinfunctions
"an array of words" wish populate, void intepreter::setbuiltins(char *builtins)
meant it's first parameter being pointer new incoming word. (and you're doing in c-style manner. well, you.)
some things consider.
if declare array
type arrname[n];
array's name being used alone without index treated variable of typetype *arrname
. if typechar *
,builtinfunctions
of typechar**
. that's whystrcpy
fails,strcpy(builtinfunctions[someindex], builtins);
works.before invoking
strcpy
should consider, if have destination space allocated.builtinfunctions[someindex]
of typechar *
. point to? valid pointer allocated space, or gateway hell of undefined behaviourstrcpy
happily take to?
Comments
Post a Comment