I want to declare my own numeric types, exactly like unsigned int, but I do not want the types to be implicitly converted. I tried this first:
typedef unsigned int firstID;
typedef unsigned int secondID;
but this is no good as the two types are just synonyms for unsigned int, so are freely interchangable.
I’d like this to cause an error:
firstID fid = 0;
secondID sid = fid; // no implicit conversion error
but this to be okay:
firstID fid = 0;
secondID sid = static_cast<secondID>(fid); // no error
My reason is so that function arguments are strongly typed, eg:
void f( firstID, secondID ); // instead of void f(unsigned int, unsigned int)
What is the mechanism I am looking for?
Thanks
Si
Maybe BOOST_STRONG_TYPEDEF form boost/strong_typedef.hpp would help.