by Usenet.9.OkianWarrior@[EMAIL PROTECTED]
Apr 15, 2008 at 08:21 PM
On Apr 15, 8:18 pm, Usenet.9.OkianWarr...@[EMAIL PROTECTED]
wrote:
> I'd like to create a new type which is polymorphic to int but has some
> different characteristics, something like this:
>
> struct ModuloInt : int { // <-- Note: class
> derives from int
> ModuloInt(int Value) : int(Value) {};
> };
>
> int main(void) {
>
> ModuloInt i = 10;
> }
>
> Neither Microsoft C++ 2008 (Express) nor gcc version 4.1 thinks this
> is legal. I've looked all over the net, but no one has an example of
> this or explains why this type of inheritance won't work.
>
> I can of course make the new class by composition and operator
> overloading, but I always thought that the builtin types were
> considered cl***** in C++.
>
> Is there a rule somewhere which states that only user-defined cl*****
> can be inherited from?
The "derives from int" in my post is part of the comment in the
previous line - it's not part of the syntax of the class definition.
Google word-wrapped it for me.