www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Static methods in interfaces?

reply Sam McCall <tunah.d tunah.net> writes:
interface Foo {
	static Foo opCall() {
		return null;
	}
}

Compiling the above code gives "function opCall function body is not 
abstract in interface Foo".
Personally, I'm in favour of letting interfaces have unrestricted static 
members, in this case to allow all implementations of the type to be 
hidden. Whether or not that's allowed, this error message is wrong.
If interfaces can have static methods, then this should compile fine.
If they can't the error should say so.
Thoughts?

Sam
Jun 29 2004
parent Charlie <Charlie_member pathlink.com> writes:
Personally, I'm in favour of letting interfaces have unrestricted static 
members, in this case to allow all implementations of the type to be 
hidden.
I disagree, I dont think interfaces should have any method bodies, but I do agree an error let u know that :) Charlie In article <cbt22d$f7i$1 digitaldaemon.com>, Sam McCall says...
interface Foo {
	static Foo opCall() {
		return null;
	}
}

Compiling the above code gives "function opCall function body is not 
abstract in interface Foo".
Personally, I'm in favour of letting interfaces have unrestricted static 
members, in this case to allow all implementations of the type to be 
hidden. Whether or not that's allowed, this error message is wrong.
If interfaces can have static methods, then this should compile fine.
If they can't the error should say so.
Thoughts?

Sam
Jun 29 2004