error C2440: '=' : cannot convert from 'const char [2]' to 'char'

Started by
5 comments, last by RigidBody 19 years, 2 months ago
I get this error: h:\CompSci1\calculater\Calculator.cpp(45): error C2440: '=' : cannot convert from 'const char [2]' to 'char' from this line of code: yesno = "Y"; it is declared as: char yesno;
-Matt S.
Advertisement
"k" is a string literal. It contains a null terminator at the end, hence two characters. 'k' denotes a character.
As a side thought, it's spelled calculator. [smile]

EDIT: I see you spelled the directory name wrong but not the source file, odd. Meh.
Well as we are nitpicking grammar.

char yesno;

Is a definition, not a declaration. =P
Replace the line with:
yesno = 'Y'; 
Use single quotes for individual characters (instead of double quotes for strings).
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Quote:Original post by RigidBody
Well as we are nitpicking grammar.


"We" weren't; the previous nitpick was about spelling.

Quote:char yesno;

Is a definition, not a declaration. =P


Good attempt, but actually it is the other way around. To "declare" something is to say it exists; to "define" it is to say what it is. Thus this is the declaration; yesno = 'Y' would be a definition. Although, my understanding of the word "grammar" has nothing to do with the meanings of words...
Quote:Original post by Zahlman
Quote:Original post by RigidBody
Well as we are nitpicking grammar.


"We" weren't; the previous nitpick was about spelling.

Quote:char yesno;

Is a definition, not a declaration. =P


Good attempt, but actually it is the other way around. To "declare" something is to say it exists; to "define" it is to say what it is. Thus this is the declaration; yesno = 'Y' would be a definition. Although, my understanding of the word "grammar" has nothing to do with the meanings of words...


You are incorrect.

extern char yesno;

is a declaration.

char yesno;

is a definition.

extern char yesno = 'a';

is a definition.

This topic is closed to new replies.

Advertisement