J
Joseph Turian
How can I create distinct sub-types of some POD?
Let me clarify:
If I do the following:
typedef unsigned T1;
typedef unsigned T2;
then I have types T1 and T2.
However, there is no type safety, and T1 and T2 can be used
interchangeably.
So this is not a viable solution, because I don't want a T1 to be
passed to a function that wants a T2.
A solution that does work, if I'm not mistaken, is to define a class T1
that stores the POD but only defines the member functions with respect
to other T1 objects. Then, duplicate that code, and s/T1/T2/g.
The problem with this solution is that if I want to create twenty
distinct types, that requires a lot of redundant code.
Is there a clean, simple way to do what I'm describing, without code
copying?
Thanks,
Joseph
Let me clarify:
If I do the following:
typedef unsigned T1;
typedef unsigned T2;
then I have types T1 and T2.
However, there is no type safety, and T1 and T2 can be used
interchangeably.
So this is not a viable solution, because I don't want a T1 to be
passed to a function that wants a T2.
A solution that does work, if I'm not mistaken, is to define a class T1
that stores the POD but only defines the member functions with respect
to other T1 objects. Then, duplicate that code, and s/T1/T2/g.
The problem with this solution is that if I want to create twenty
distinct types, that requires a lot of redundant code.
Is there a clean, simple way to do what I'm describing, without code
copying?
Thanks,
Joseph