Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C - C++ Learning > Re: Inheriting ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 5 Topic 4117 of 4302
Post > Topic >>

Re: Inheriting from built-in types

by "A. W. Dunstan" <no@[EMAIL PROTECTED] > Apr 21, 2008 at 09:58 AM

Ian Collins wrote:

> Usenet.9.OkianWarrior@[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;
>>     }
>> 
> No, you can't do this.
> 
>> 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++.
>> 
> No they are not.  Maybe you are thinking of Java?
> 
Even in Java you can't derive from int - that's a 'native data type', and
not a class.  "Integer" is a class, but since it's 'final' you can't
derive
from it, either.  Ruby and C# (and other) will let you derive from int, as
they treat int (and float, and double, etc) as full-fledged objects.


-- 
Al Dunstan, Software Engineer
OptiMetrics, Inc.
3115 Professional Drive
Ann Arbor, MI  48104-5131
 




 5 Posts in Topic:
Inheriting from built-in types
Usenet.9.OkianWarrior@[EM  2008-04-15 20:18:57 
Re: Inheriting from built-in types
Usenet.9.OkianWarrior@[EM  2008-04-15 20:21:51 
Re: Inheriting from built-in types
Ian Collins <ian-news@  2008-04-16 16:18:20 
Re: Inheriting from built-in types
"A. W. Dunstan"  2008-04-21 09:58:22 
Re: Inheriting from built-in types
Andrey Tarasevich <and  2008-04-16 16:27:24 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 13 4:26:24 CDT 2008.