Re: Some confusion about datatypes and classes
  Home FAQ Contact Sign in
alt.comp.lang.learn.c-c++ only
 
Advanced search
POPULAR GROUPS

more...

alt.comp.lang.learn.c-c++ Profile…
 Up
Re: Some confusion about datatypes and classes         


Author: Francis Glassborow
Date: Jan 19, 2007 04:01

In article , James Dennett
acm.org> writes
>You could just use long, and it would work -- or do you have
>some specific requirements on range checking or wraparound?
>If so, using a class and operator overloading would be the
>way to go.
It is actually quite hard to produce a class type that behaves like an
integer type but has some added constraint unless one forgoes implicit
outward conversions (i.e. do not provide any conversion operators)

--
Francis Glassborow ACCU
Author of 'You Can Do It!' and "You Can Program in C++"
see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
1 Comment
Re: Some confusion about datatypes and classes         


Author: James Dennett
Date: Jan 19, 2007 07:07

Francis Glassborow wrote:
> In article , James Dennett
> acm.org> writes
>> You could just use long, and it would work -- or do you have
>> some specific requirements on range checking or wraparound?
>> If so, using a class and operator overloading would be the
>> way to go.
> It is actually quite hard to produce a class type that behaves like an
> integer type but has some added constraint unless one forgoes implicit
> outward conversions (i.e. do not provide any conversion operators)

If seeking a theoretically perfect solution, that's
true.

In a specific application, it's generally much more
straightforward. (And forgoing implicit outward
conversions is often a good way to go.)

-- James
no comments