C++ problem (one last try)

Björn Lindberg d95-bli at nada.kth.se
Mon Aug 9 07:45:02 PDT 2004


michael <michael8110 at terra.com.br> writes:

> Sorry for my mistake,i was really confusing the declaration of an
> array  e.g. char a[20]  with the 21st element a[21],so the keyboard
> recovered :-).
> But,the below code seems to be free of such mistakes,uses a
> constructor  (that should be then initialisation) but still gives the
> same error  message,
> error: incompatible types in assignment of `char*' to `char[20]'  on
> line  7.As far as i can see,i'm assigning char* to char*,or?

You better trust the compiler before yourself. :-) The compiler is
usually right, even this time. The type of itsName is 'char[20]', not
'char *'. Even so, that assignment is wrong on more than one
level. Most importantly, that is not how you do to fill an array with
the contents of another array. For that you need strcpy() or a loop
assigning the array elements element-wise.

If you tell us what you are trying to accomplish, perhaps we can be of
more help?


Björn



More information about the lfs-chat mailing list