Hi,

I am trying to figure out the singleton pattern with a struct instead of a class:
[code]
struct Singleton  {

private :
        this( int a = 0 ) {} ;
        static Singleton * s ;

public :
        @disable this() ;
        static ref Singleton instance()  {
                if ( s is null )
                        s = new Singleton( 0 ) ;
                return * s ;
        }
        
        int val = 0 ;
}
[/code]

This compiles, but when I use it:
[code]
        auto s = Singleton.instance ;
        writeln( s.val ) ;

        Singleton.instance.val = 2 ;
        writeln( s.val ) ;
[/code]

I get:
0
0

Where is my mistake ?

Cheers, PP !

Reply via email to