www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - template interfaces

reply "Bruno A. Costa" <bruno codata.com.br> writes:
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.
~
Jun 29 2004
parent reply Hauke Duden <H.NS.Duden gmx.net> writes:
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
Jun 29 2004
parent "Bruno A. Costa" <bruno codata.com.br> writes:
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.
Jun 29 2004