class MyType
{
public:
A ( unsigned _a ) : a (_a-1)
{
}
operator unsigned& ()
{
return a;
}
operator const unsigned () const
{
return a;
}
unsigned a;
};
In the above example, I created a class MyType which is comprised of just one unsigned integer.
is there a design pattern name for MyType? It is a unsigned integer and it could be use as one. But just with a different name
Don’t know what the design pattern name is, but there is a use for it.
It can be useful if you have a set of classes that all implement that same member functions, and you want to treat them all in the same way. Some of these classes contain simple types like
intandunsigned, while others contain more complicated class/struct types.The goal is to allow “boxed” primitive types to act like the more complicated “real” class types. This is especially useful when these classses can all be used as template parameters within a group of template classes or functions (i.e., when all of the classes inherit the same base interface class(es)).