This is a part of a big code that I have got, and there is a part that at the moment I dont know what it's doing
1 2 3 4 5 6 7
stream & operator << (ostream & os,DigBCD a) {
stream & operator << (ostream & os,DigBCD a) {
os << char(Dig2Char(a)+'0');
return os;
}
return os;
}
I know It is overloading operator << but I dont understand this part..
1 2 3
os << char(Dig2Char(a)+'0');
Dig2char is returning a char...It seems like a casting but I dont understande why it's a casting because It return a char and the casting(if it's what I think) is promotining to a char...and I do not understand how is plus '0'...maybe the addiction with a char is the key...somebody has an idea???
char Dig2Char(DigBCD a) {
switch (a) {
case c:
return'0';
case u:
return'1';
case d:
return'2';
case t:
return'3';
case q:
return'4';
case z:
return'5';
case x:
return'6';
case s:
return'7';
case o:
return'8';
case n:
return'9';
case E:
default:
return'E';
}
}