Boost logo

Boost :

From: Maciej Sobczak (maciej_at_[hidden])
Date: 2002-10-24 06:11:41


Terje Slettebo wrote:
>>From: "Maciej Sobczak" <maciej_at_[hidden]>
>
>
>>The mathematics is the same in ancient Rome, in Warsaw and in Tokyo,
>>even if the numbers *look* differently.
>
>
>>I think that the representation of the class should be separate from the
>>class. You can achieve this with either separate translator functions
>>(see the reply from Volodya) or by wrapping integer into some class:
>
>
>>int i = ...;
>>cout << MyNumber(i);
>>
>>MyNumber n;
>>cin >> n;
>>int i = n.get();
>
>
> How is MyNumber different from a Roman number class? It seems to me that it
> does indeed represent Roman numbers.

No. It is just a way to add type information to the built-in type so
that the operator overloading can kick in. It is enough to write:

struct MyNumber
{
        MyNumber(int v) : value_(v) {}
        int value_;
};

(whether you use get() accessor or directly access the value_ memember
can be left here as a matter of taste)

and do the proper formatting in the inserter/extractor operator
overloaded for MyNumber.
One could go to extremes with this concept and write template for
wrapping different built-in types, even many times, but for the sake of
this discussion the struct above is really enough.

The idea of wrapping built-in type this way comes from my initial
statement - math does not change across countries (so let's use ints for
math and other stuff for representation).

Cheers,

---
Maciej Sobczak
http://www.maciejsobczak.com/

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk