Thread overview
another question about interfaces
Apr 14, 2004
Ivan Senji
Apr 15, 2004
Russ Lewis
Apr 15, 2004
Ivan Senji
Apr 15, 2004
Ivan Senji
April 14, 2004
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?




April 15, 2004
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?

April 15, 2004
"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.




April 15, 2004
"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() {...};
> }

HM! I tried something like this in C# but it doesnt work there either. But it would be very useful in D :)