Petec posted:
> Ray Gardener wrote:
>> C++ doesn't allow:
>>
>> class counter : public int {};
>>
>>
>> Was there any special reason why base class ids can only be
>> struct/class ids? This limitation appears to violate the
>> concept of uniform type conceptualization; i.e. classes
>> can never have or extend an is-a relationship to a scalar.
>>
>>
>> Ray Gardener
>> Daylon Graphics Ltd.
>> http://www.daylongraphics.com
>> "Heightfield modeling perfected"
>
> While that's not allowed, you can do something like:
>
> class counter
> {
> int base;
> public:
> counter(int b): base(b) {}
> operator int() {return base;}
>
> /* operators such as + * - / ++ -- etc */
> };
>
> I believe that has the same effect as the one you want...
>
> - Pete
I would suggest piggybacking on the predefined intrinsic int operators, by
defining an int cast operator:
counter:

perator int(void)
{
return base;
}
And then, when something tries to mess with your "base" value, which
ofcourse will be protected, you can interfer:
counter:

perator= (int& sauce)
{
if //....
}