Define a templated wrapper class for your primitives. Due to a sudden deficit in imagination, I'll call it Wrapper. It goes something like:
class Magic {};template <typename T, Magic & m>class Wrapper { public: Wrapper() {} Wrapper(T data) : data_(data) {} // copy constructers, operator=, etc. Wrapper & operator+=(const Wrapper & rhs) { data_ += rhs.data_; } // other arithmetic operatoers, etc. private: T data_;};extern Magic FooMagic;typedef Wrapper<int, FooMagic> Foo;extern Magic BarMagic;typedef Wrapper<int, BarMagic> Bar;bool valid(Foo i);bool valid(Bar j);int main(int, char **) { Foo i; Bar j; return 0;}
edit: the key is that templates parameterized on different non type template parameters are separate types. So by using the symbols FooMagic and BarMagic, you can totally disambiguate the Wrapper types. No inheritance, so no slicing issues and no weird implicit conversions can make the compiler think that the two types are related.
edit: I can't spell today
[edited by - SiCrane on April 3, 2004 10:39:20 PM]