static vs non-static

Zhenya zheny at list.ru
Sun Jan 13 10:16:38 PST 2013


On Sunday, 13 January 2013 at 17:59:28 UTC, Andrey wrote:
> Don't know if this will be useful in any manner, but it came 
> this silly way:
>
> class MyClass {
>
> 	struct _static {
>
>  		static void myfun() {
>  			writeln("static myfun");
>  		}
> 	}
>
>  	void myfun() {
>  		writeln("myfun");
>  	}
>
> }
>
> void main() {
>
> auto obj = new MyClass();
> obj.myfun(); //myfun
> obj._static.myfun(); //static
> MyClass._static.myfun(); //static
>
> }
Aha...Thank you,very interesting idea to hide function in struct:


struct Foo
{
	static struct bar
	{
	static void opCall()
	{
		writeln("static");
	}
	void bar()
	{
		writeln("non-static");
	}
	}
}

This is the workaround I looked for.


More information about the Digitalmars-d-learn mailing list