error C2440: '=' : cannot convert from 'const char [2]' to 'char'
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;
"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.
EDIT: I see you spelled the directory name wrong but not the source file, odd. Meh.
Replace the line with:
yesno = 'Y';
Use single quotes for individual characters (instead of double quotes for strings).
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 ZahlmanQuote: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
Popular Topics
Advertisement