A
Alan Johnson
For various reasons I'd like to be able to inherit from the built in
types, which obviously you cannot do. To get around this, I made a
template to emulate the built in types. So far I can't find any
situations in which this template fails to work interchangably with the
built in types. My question is if anyone knows of any gotcha type
situations in which this is going to fail.
Thanks,
Alan
template <typename T>
class built_in
{
private :
T value ;
public :
built_in() {}
built_in(const T &t) : value(t) {}
operator T() const { return value ; }
operator T&() { return value ; }
T &operator=(const T &t) { return (value = t) ; }
T &operator %=(const T &t) { return value %= t ; }
T &operator &=(const T &t) { return value &= t ; }
T &operator |=(const T &t) { return value |= t ; }
T &operator ^=(const T &t) { return value ^= t ; }
T &operator +=(const T &t) { return value += t ; }
T &operator -=(const T &t) { return value -= t ; }
T &operator *=(const T &t) { return value *= t ; }
T &operator /=(const T &t) { return value /= t ; }
T &operator <<=(const T &t) { return value <<= t ; }
T &operator >>=(const T &t) { return value >>= t ; }
T* operator&() { return &value } ;
} ;
types, which obviously you cannot do. To get around this, I made a
template to emulate the built in types. So far I can't find any
situations in which this template fails to work interchangably with the
built in types. My question is if anyone knows of any gotcha type
situations in which this is going to fail.
Thanks,
Alan
template <typename T>
class built_in
{
private :
T value ;
public :
built_in() {}
built_in(const T &t) : value(t) {}
operator T() const { return value ; }
operator T&() { return value ; }
T &operator=(const T &t) { return (value = t) ; }
T &operator %=(const T &t) { return value %= t ; }
T &operator &=(const T &t) { return value &= t ; }
T &operator |=(const T &t) { return value |= t ; }
T &operator ^=(const T &t) { return value ^= t ; }
T &operator +=(const T &t) { return value += t ; }
T &operator -=(const T &t) { return value -= t ; }
T &operator *=(const T &t) { return value *= t ; }
T &operator /=(const T &t) { return value /= t ; }
T &operator <<=(const T &t) { return value <<= t ; }
T &operator >>=(const T &t) { return value >>= t ; }
T* operator&() { return &value } ;
} ;