🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.lenguajes.c++
Article #95

Re: Crear clase dígito.

#95
From: Pascal J. Bourguignon
Date: Fri, 02 May 2008 15:16
27 lines
2232 bytes
"R.G.A.M." <rgam1989@yahoo.com.ar> writes:

> Me gustar�a saber c�mo puedo dise�ar un objeto de la misma naturaleza
> que la clase "int", salvo que s�lo abarque los n�meros del 0 al 9,
> para poder trabajar �nicamente con d�gitos, sin derrochar memoria.
>
> Desde ya, muchas gracias.

Tipos enteros y objetos no son de la misma naturaleza en C++.
No se puede escribir: 42.print();


typedef unsigned char digit; // misma naturaleza

o bien:

class digit {                // un objeto
protected: unsigned char value;
digit(unsigned char aValue):value(aValue){assert((0<=aValue)&(aValue<=9));}
inline int getValue(void)const{return value;}
const digit& operator+(const digit& other){return(digit((value+other.getValue())%10));}
// ...
}; 


-- 
__Pascal Bourguignon__
Technical Details
Message-ID: <7cprs4zqgl.fsf@pbourguignon.anevia.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!cleanfeed2-a.proxad.net!nnrp8-1.free.fr!not-for-mail
References: <b8d26aa2-7a81-4015-b46c-65bf259d1ceb@b1g2000hsg.googlegroups.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: f53ec,2b546618fd129871
X-Google-Attributes: gidf53ec,domainid0,public,usenet
X-Google-Language: SPANISH,ASCII
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!cleanfeed2-a.proxad.net!nnrp8-1.free.fr!not-for-mail
Newsgroups: es.comp.lenguajes.c++
Subject: Re: Crear clase dígito.
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA
      oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9
      033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac
      l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR
      mV+hO/VvFAAAAABJRU5ErkJggg==
X-Accept-Language:         fr, es, en
X-Disabled: X-No-Archive: no
References: <b8d26aa2-7a81-4015-b46c-65bf259d1ceb@b1g2000hsg.googlegroups.com>
From: pjb@informatimago.com (Pascal J. Bourguignon)
Date: Fri, 02 May 2008 17:16:26 +0200
Message-ID: <7cprs4zqgl.fsf@pbourguignon.anevia.com>
Organization: Anevia SAS
User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.1 (gnu/linux)
Cancel-Lock: sha1:IvjxoV3jShjh7DT11ay11hoymOg=
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Lines: 27
NNTP-Posting-Date: 02 May 2008 17:16:27 MEST
NNTP-Posting-Host: 88.170.236.224
X-Trace: 1209741387 news-2.free.fr 4296 88.170.236.224:42127
X-Complaints-To: abuse@proxad.net