Reputation: 57
I am getting this error -- error: default initialization of an object of const type 'const char'
my code is in c and the error is in my .h file.. this is what the code looks like that is getting the errors
const char *c2ptr[37]={ 0, 4, 8,11,14,16,18,20,23,25,
27,29, 3,31,34,37, 3, 3,39,44,
48,51,54,57,60, 3,62,65, 3,68,
72,75, 3,77,79,81,84},
ch,inif,*fname,
comf[4]={ 7, 8, 9,13};
and so... the errors all pop up on the ch,inif,*fname... does it have to do with the fact that they are not arrays? as far as i know this is legal.
Upvotes: 2
Views: 8194
Reputation: 40934
Your code declares four variables:
c2ptr
of items of type const char*
ch
of type char
inif
of type char
fname
of type const char*
comf
of items of type char
First of all, c2ptr
is an array of const char*
(strings), but your code initializes it to a list of int
, { 0, 4, 8, 11, ... }
.
Secondly, your variables ch
and inif
are constants, but haven't been assigned a value to them. Since a constant variable can't be changed, you must assign a value to them in the declaration. (This is probably what's giving you errors.)
Upvotes: 4
Reputation: 53036
You declared the array for const char *
pointers, and initialized it with int
, maybe you meant
static const char *c2ptr[37] = {
"0", "4", "8", "11", "14", "16", "18", "20", "23", "25",
"27", "29", "3", "31", "34", "37", "3", "3", "39", "44",
"48", "51", "54", "57", "60", "3", "62", "65", "3", "68",
"72", "75", "3", "77", "79", "81", "84"
};
Upvotes: 1