From 8ea54871577c6d32ef579c1587dfd4eda3f36ddf Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Sat, 27 Sep 2003 18:43:05 +0000 Subject: [PATCH] Ya compilan Ascii y Unicode. --- ascii.cpp | 11 +++++++++-- ascii.h | 5 ++++- unicode.cpp | 13 +++++++++---- unicode.h | 11 ++++++++--- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/ascii.cpp b/ascii.cpp index f4b72d8..9a0982c 100644 --- a/ascii.cpp +++ b/ascii.cpp @@ -20,7 +20,7 @@ # include #endif -Ascii::Ascii(char c = '0'): caracter(c) { +Ascii::Ascii(char c): caracter(c) { #ifdef DEBUG std::cerr << "En constructor de Ascii." << std::endl; #endif @@ -60,7 +60,14 @@ bool Ascii::operator==(const Ascii& ascii) { return caracter == ascii.caracter; } -short Ascii::operator short(void) { +Ascii::operator char(void) const { +#ifdef DEBUG + std::cerr << "En cast de Ascii a char." << std::endl; +#endif + return static_cast(caracter); +} + +Ascii::operator short(void) const { #ifdef DEBUG std::cerr << "En cast de Ascii a short." << std::endl; #endif diff --git a/ascii.h b/ascii.h index cbf9f94..86c0322 100644 --- a/ascii.h +++ b/ascii.h @@ -50,8 +50,11 @@ class Ascii { /// ComparaciĆ³n por igual de dos instancias. bool operator==(const Ascii& ascii); + /// Cast a char. + operator char(void) const; + /// Cast a short. - short int Ascii::operator short int(void); + operator short(void) const; /// Volcado a un stream de salida. friend std::ostream& operator<<(std::ostream& out, const Ascii& ascii); diff --git a/unicode.cpp b/unicode.cpp index f1a0ad7..c0bfa8f 100644 --- a/unicode.cpp +++ b/unicode.cpp @@ -20,7 +20,7 @@ # include #endif -Unicode::Unicode(short c = 0): caracter(c) { +Unicode::Unicode(short c): caracter(c) { #ifdef DEBUG std::cerr << "En constructor de Unicode." << std::endl; #endif @@ -60,14 +60,20 @@ bool Unicode::operator==(const Unicode& unicode) { return caracter == unicode.caracter; } -char Unicode::operator char(void) { +Unicode::operator short(void) const { +#ifdef DEBUG + std::cerr << "En cast de Unicode a char." << std::endl; +#endif + return static_cast(caracter); +} + +Unicode::operator char(void) const { #ifdef DEBUG std::cerr << "En cast de Unicode a char." << std::endl; #endif return static_cast(caracter); } -/// Volcado a un stream de salida. std::ostream& operator<<(std::ostream& out, const Unicode& unicode) { #ifdef DEBUG std::cerr << "En operator<< de Unicode." << std::endl; @@ -75,7 +81,6 @@ std::ostream& operator<<(std::ostream& out, const Unicode& unicode) { return out << unicode.caracter; } -/// Captura desde un stream de entrada. std::istream& operator>>(std::istream& in, const Unicode& unicode) { #ifdef DEBUG std::cerr << "En operator>> de Unicode." << std::endl; diff --git a/unicode.h b/unicode.h index 1eeb1d8..f232b67 100644 --- a/unicode.h +++ b/unicode.h @@ -51,13 +51,18 @@ class Unicode { bool operator==(const Unicode& unicode); /// Cast a char. - char Unicode::operator char(void); + operator char(void) const; + + /// Cast a char. + operator short(void) const; /// Volcado a un stream de salida. - friend std::ostream& operator<<(std::ostream& out, const Unicode& unicode); + friend std::ostream& operator<<(std::ostream& out, + const Unicode& unicode); /// Captura desde un stream de entrada. - friend std::istream& operator>>(std::istream& in, const Unicode& unicode); + friend std::istream& operator>>(std::istream& in, + const Unicode& unicode); }; -- 2.43.0