comp.lang.ada
 help / color / mirror / Atom feed
From: "REH" <spamjunk@stny.rr.com>
Subject: Re: Type safety, C++ and code generation
Date: 2 May 2006 06:33:17 -0700
Date: 2006-05-02T06:33:17-07:00	[thread overview]
Message-ID: <1146576797.106931.267280@i40g2000cwc.googlegroups.com> (raw)
In-Reply-To: <e36u45$s2s$1@sunnews.cern.ch>


Maciej Sobczak wrote:
> Martin Krischik wrote:
>
> >>What about making different types really distinct?
> >>
> >>typedef ranged_type<int, 0, 100> R1;
> >>typedef ranged_type<int, 0, 100> R2;
> >>typedef ranged_type<int, 0, 101> R3;
> >>
> >>
> >>Above, R1 and R2 are equal to the compiler
>
> > This is because "typdef" in C++ is "subtype" in Ada.
>
> Not really - you cannot add constraints with typedef. ;)
>
> > You would need:
> >
> > class R1 : ranged_type<int, 0, 100> {};
> > class R2 : ranged_type<int, 0, 100> {};
> > class R3 : ranged_type<int, 0, 101> {};
> >
> > to create new types.
>
> Except that those new types would be problematic to use with operations
> that are already defined for ranged_type (especially those which return
> ranged_type), because there is no implicit conversion to the derived class.
>
That's not true.  operators are usually defined using references.  A
reference to a child class is alway implicitly convertable to a
reference to its parent class.  The only issues with the above are: 1)
it should use public inheritance, not private to allow the user access
to any member function that may be defined (i.e., member operators).
2) it has no constructors, because they are not inherited. 3) assigning
the result back to an object of the child class requires a constructor
to be defined.

REH




  reply	other threads:[~2006-05-02 13:33 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-27 10:35 Type safety, C++ and code generation Maciej Sobczak
2006-04-27 13:19 ` REH
2006-04-27 14:08   ` Maciej Sobczak
2006-04-27 14:33     ` REH
2006-04-27 15:16       ` Maciej Sobczak
2006-04-27 15:39         ` Georg Bauhaus
2006-04-28  5:57           ` Maciej Sobczak
2006-04-28 12:16             ` Georg Bauhaus
2006-04-28 12:37               ` brian.b.mcguinness
2006-04-28 17:04                 ` Georg Bauhaus
2006-04-28 18:50                 ` Jeffrey R. Carter
2006-04-28 19:07                   ` Randy Brukardt
2006-04-28 19:46                     ` Robert A Duff
2006-04-28 19:55                   ` Dmitry A. Kazakov
2006-04-29 21:28               ` Florian Weimer
2006-04-27 16:05         ` REH
2006-04-28  6:17           ` Maciej Sobczak
2006-04-30 14:40         ` adaworks
2006-04-30 15:23           ` REH
2006-04-30 18:14         ` Martin Krischik
2006-05-02  6:27           ` Maciej Sobczak
2006-05-02 13:33             ` REH [this message]
2006-05-02 15:05               ` Maciej Sobczak
2006-05-02 15:54                 ` REH
2006-05-02 16:50               ` Martin Krischik
2006-05-02 19:50                 ` REH
2006-04-27 14:47     ` REH
2006-04-27 15:10     ` REH
2006-04-28  6:22       ` Maciej Sobczak
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox