www.digitalmars.com         C & C++   DMDScript  

D - another question about interfaces

reply "Ivan Senji" <ivan.senji public.srce.hr> writes:
why can't interfaces contain static functions?

for example:

interface IElement
{
    static IElement create(){...}
}

I would expect that the class implementing this interface must
define "static IElement create()"
but if it doesn't the compiler doesn't complain
and if it does implement this function I get a linker error?
Apr 14 2004
parent reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
My thought is that an interface defines an interface into a class. 
Interfaces don't actually implement anything.  So you would do something 
like this:

interface IElement
{
	static IElement create();
}

class Foo : IElement
{
	static IElement create() {...};
}



Ivan Senji wrote:
 why can't interfaces contain static functions?
 
 for example:
 
 interface IElement
 {
     static IElement create(){...}
 }
 
 I would expect that the class implementing this interface must
 define "static IElement create()"
 but if it doesn't the compiler doesn't complain
 and if it does implement this function I get a linker error?
Apr 14 2004
next sibling parent "Ivan Senji" <ivan.senji public.srce.hr> writes:
"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:c5l2m7$t9j$1 digitaldaemon.com...
 My thought is that an interface defines an interface into a class.
 Interfaces don't actually implement anything.  So you would do something
 like this:

 interface IElement
 {
 static IElement create();
 }

 class Foo : IElement
 {
 static IElement create() {...};
 }
OOps I am sorry this is what i wanted to write, the {}in the interface are a typing error. The actual code looks just like the one you wrote but it doesnt work. If class Foo does implement IElement but it doesn't implement "static IElement create()" this isn't an error but even if it does implement it i get a linker error.
Apr 14 2004
prev sibling parent "Ivan Senji" <ivan.senji public.srce.hr> writes:
"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:c5l2m7$t9j$1 digitaldaemon.com...
 My thought is that an interface defines an interface into a class.
 Interfaces don't actually implement anything.  So you would do something
 like this:

 interface IElement
 {
 static IElement create();
 }

 class Foo : IElement
 {
 static IElement create() {...};
 }
But it would be very useful in D :)
Apr 15 2004