Why can't structs be derived from?

Simen kjaeraas simen.kjaras at gmail.com
Wed Mar 16 13:49:53 PDT 2011


On Wed, 16 Mar 2011 16:23:47 +0100, Steven Schveighoffer  
<schveiguy at yahoo.com> wrote:

> struct Point2 {
>     int x, y;
>     void draw(Canvas c) {...}
> }
>
> struct Point3 : Point2 {
>     int z;
>     void draw(Canvas c) {...}
> }
>
> Point3 p3;
> Point2 *p2 = &p3;
>
> // what does this do?
> p2.draw(c);

Nothing. You should got a type error upon attempting to assign a p3* to a  
p2*.

-- 
Simen


More information about the Digitalmars-d mailing list