Problem using Interfce

John Chapman johnch_atms at hotmail.com
Mon May 14 04:29:09 PDT 2012


On Monday, 14 May 2012 at 11:08:09 UTC, Stephen Jones wrote:
> I have a Widget interface which I was hoping would allow me to
> subsume a set of classes {Button, Cursor, etc} as being Widgets
> so I could keep an array of buttons, cursors, etc by 
> initializing
> them as Widgets.
>
> private Widget[] widgets;
> ...
> widgets[widx++]=new Button(fmt, unitw, unith, count);
> ...
> widgets[widx++]=new Cursor(unitw, unith, count);
>
>
> But when I try to step through the array I cannot access Button
> or Cursor variables because "Error: no property 'vertStart' for
> type 'Widget.Widget'":
>
> foreach(Widget w; widgets){
>     glDrawArrays(GL_TRIANGLES, w.vertStart, w.vertCount);
> }
>
>
> I am used to languages where the w under consideration in any
> iteration would be known to have been initialized as a Button or
> Cursor, etc, and the value of vertStart would be found without
> error. I cannot cast without wrapping everything in if
> statements. I could use access functions but I would prefer not
> to incur function overhead. Is there a solution?

Are you compiling with the -property switch? If so, vertStart and 
vertCount must be declared with the @property attribute. 
Otherwise invoke them like regular functions, i.e., vertStart() / 
vertCount().


More information about the Digitalmars-d-learn mailing list