I need a strong typed integer in C ++ that compiles in Visual Studio 2010.
I need this type to act as an integer in some patterns. In particular, I must be able to:
StrongInt x0(1); //construct it. auto x1 = new StrongInt[100000]; //construct it without initialization auto x2 = new StrongInt[10](); //construct it with initialization
I have seen things like:
class StrongInt { int value; public: explicit StrongInt(int v) : value(v) {} operator int () const { return value; } };
or
class StrongInt { int value; public: StrongInt() : value(0) {}
Since these things are not PODs, they do not quite work.
source share