Thread overview
template interfaces
Jun 29, 2004
Bruno A. Costa
Jun 29, 2004
Hauke Duden
Jun 29, 2004
Bruno A. Costa
June 29, 2004
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
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
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.