Thread overview | |||||
---|---|---|---|---|---|
|
June 29, 2004 template interfaces | ||||
---|---|---|---|---|
| ||||
Is it possible to write template interfaces in D? I am making this question because the compiler accepts the following code: interface Foo (T) { public: void do_something (); } class Bar(T) : Foo { // <-- this is line 8 void do_something ( ) { } } //----------------------------- but if I append the main function: int main () { Bar!(int) b = new Bar!(int); return 0; } //----------------------------------------- the compiler returns this error: dmd -c iface.d iface.d(8): template Foo(T) is used as a type iface.d(8): class Bar base type must be class or interface, not void Thanks Bruno. ~ |
June 29, 2004 Re: template interfaces | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bruno A. Costa | Bruno A. Costa wrote:
> Is it possible to write template interfaces in D?
>
>
>
> I am making this question because the compiler accepts the following code:
>
> interface Foo (T)
> {
> public:
> void do_something ();
> }
>
> class Bar(T) : Foo
> { // <-- this is line 8
> void do_something ( ) { }
> }
>
> //-----------------------------
>
>
>
> but if I append the main function:
>
> int main ()
> {
> Bar!(int) b = new Bar!(int);
> return 0;
> }
> //-----------------------------------------
>
> the compiler returns this error:
>
> dmd -c iface.d
> iface.d(8): template Foo(T) is used as a type
> iface.d(8): class Bar base type must be class or interface, not void
Try this:
class Bar(T) : Foo!(T)
{
...
Hauke
|
June 29, 2004 Re: template interfaces | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hauke Duden | Hauke Duden wrote: > Bruno A. Costa wrote: >> Is it possible to write template interfaces in D? >> >> >> > > Try this: > > class Bar(T) : Foo!(T) > { > ... > > > Hauke Ok, it worked :) Thanks. Bruno. |
Copyright © 1999-2021 by the D Language Foundation