2

I need to create many classes that are somewhere between integer and enum. I.e. have the arithmetics of integer but also are not implicitly converted to int.

2 Answers 2

4

Have a look at the answer to this question - BOOST_STRONG_TYPEDEF did exactly what I wanted.

// macro used to implement a strong typedef. strong typedef // guarentees that two types are distinguised even though the // share the same underlying implementation. typedef does not create // a new type. BOOST_STRONG_TYPEDEF(T, D) creates a new type named D // that operates as a type T. 
Sign up to request clarification or add additional context in comments.

Comments

1

One possibility is to create a class with the "enums" defined as invariant members of the class with a ::GetValue() method and the mathematical operations you need to use overloaded to use GetValue() to do the math in question.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.